Re: Declaring large (but not that large) array causes crash?
Re: Declaring large (but not that large) array causes crash?
- Subject: Re: Declaring large (but not that large) array causes crash?
- From: Dan Sugalski <email@hidden>
- Date: Mon, 22 Sep 2003 16:26:32 -0400 (EDT)
On Mon, 22 Sep 2003, Thomas McQuitty wrote:
>
And, unless you are using that chunk of memory all the time, you
>
shouldn't declare it as a fixed array, anyway. Using a dynamic
>
structure allows for more flexibility in only using the memory needed
>
and allows you to grow the array size, if needed.
Well, if you've got pointer aliasing disabled there are a number of
optimizations that can be done if the array size is fixed and known at
compile-time, though I'm not sure if GCC uses that information. (And odds
are with that sort of code you're probably using a fortran compiler or
something, but still...)
>
On Monday, September 22, 2003, at 01:43 PM, Dan Sugalski wrote:
>
>
> On Mon, 22 Sep 2003, John Scalo wrote:
>
>
>
>> Sorry, this isn't Cocoa-related per se, but it is crashing my Cocoa
>
>> program
>
>> :-(
>
>>
>
>> Declaring an array with a lot of items always causes a crash.
>
>>
>
>> int main (int argc, const char * argv[]) {
>
>> unsigned long notSoBigArray[200000];
>
>> return 0;
>
>> }
>
>>
>
>> That's only about 780K. Why the crash?
>
>
>
> Because you blew your stack in a big way, I expect. Stack space, in
>
> threaded applications, is pretty limited--usually less than 1M, often
>
> as
>
> low as 20-40K. (Depends on the platform and all)
>
>
>
> For something that size, malloc the memory instead.
>
>
>
> Dan
>
> _______________________________________________
>
> cocoa-dev mailing list | email@hidden
>
> Help/Unsubscribe/Archives:
>
> http://www.lists.apple.com/mailman/listinfo/cocoa-dev
>
> Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.