Mail Archives: djgpp/1996/07/28/14:14:43
>
> Wow, thanks a lot. I to malloc a meg and it worked just fine. But, when
> I tried to defind a static array (ie- char Array[1024 * 1024]) I got a
> wierd runtime error
>
> Exiting due to signal SIGSEGV
> Stack fault at ...
> eax=...
> ebp=...
> Call from traceback EIPs:
> 0x000015b9
>
> (the ...'s should be replaced with a ton of numbers and info).
>
> I tried to allocate the array on the first line of the main function.
> The rest of the program is simply printf statements (except for a line
> that sets one of the array values to 5, but it never gets that far). Is
> there something wrong with allocating a buffer this way?
void main (void)
{ char Array[1024*1024]; ...}
Array is put on the stack. But there is only 256Kb on the stack, so the rest
of your stack is all over your program. Anyway it is bad practice to use large
amounts of stack. You should allocate it dynamically if you want big amounts
of memory.
char Array[1024*1024];
void main ( void )
{ ... }
Array is now static: ie a 1Mb array is made inside your executable, working but
leading to a bloated >1Mb executable!
Third choice: malloc: dynamic, no disadvantages.
Sengan
- Raw text -