Archived

This topic is now archived and is closed to further replies.

Craazer

How much memory compiler can allocate automaticly?

Recommended Posts

Hi You know that if you have line like this: int too_big_array[1000000]; your application probably crashes becose that's too much memory space to have. So my only queston is what is the limit? (in other words at what point should i use new) [edited by - Craazer on August 5, 2003 10:27:52 AM]

Share this post


Link to post
Share on other sites
There is no strict limit. These arrays may be created on the stack. In MSVC, for instance, you can change it using the /STACK linker option (the default value is 1MB: /STACK:1048576). The array you''re talking about is just under 4MB in size.

Using the stack is probably a bad idea, because you will most likely not be able to predict how much of the stack will be used at all times. Personally, I start using new when the amount needed exceeds 64K.

Share this post


Link to post
Share on other sites
Most linkers have stack size setting (i don't remember the defaults).
However, if you are going to allocate masses of memory, it's always better to allocate it yourself with new.
If for nothing else, you can at least respond to out-of memory errors in a controlled manner.

[edited by - Nik02 on August 5, 2003 10:50:44 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by Kippesoep
There is no strict limit. These arrays may be created on the stack. In MSVC, for instance, you can change it using the /STACK linker option (the default value is 1MB: /STACK:1048576). The array you''re talking about is just under 4MB in size.

Using the stack is probably a bad idea, because you will most likely not be able to predict how much of the stack will be used at all times. Personally, I start using new when the amount needed exceeds 64K.




Ok I gues I''l just use the new thingy to be sure it works.

Thanks for the info.

Share this post


Link to post
Share on other sites
Oh, BTW, I forgot: if you use globals, then these arrays are allocated on the heap, not the stack. There''s also a /HEAP option, which does the same for the heap size (with the same default value).

Share this post


Link to post
Share on other sites