i am having memory problems w/ my program - using SDL

Started by
4 comments, last by christ-heffer 21 years, 10 months ago
/-----------------------------------\ | skip here to get to the real problem-/ | i am using SDL (simple directmedia layer) www.libsdl.org to write my program (my largest attempt in c++ yet). my program | was going great. of course i encountered bugs, even ones i thought i wasnt going to be able to fix, but then i fixed them and | i was really excited when the path was clear of major bugs and the rest was easy finetuning type stuff. V when i declared too many or too large of arrays (for storing and handling image data) the program automatically cut off even w/o leaving error info in the error file. the size of the arrays are directly related to the dimensions of the image i load. this is the maximum array space i have been able to allocate w/o crashing Uint32[358][268], int[358][268], int[358][268], int[358][268], int[358][268] so, 95944 slots in 32 bit arrays, 383776 slots in integer arrays why would my prgoram cut off? is there a RAM max for programs using the tools i have? i have 256meg ram. other programs must have to allocate a lot more than that. i am using DevC++ 4.1 and a Ming32 compiler Dell Dimension 450mhz P2 256meg RAM, 13gb hd ntvidia somthing-or-other ANY SUGGESTIONS? (only loading images 358x268 is not a possibility, i need to load images as larage as 800x600, and i need all the arrays too)
Advertisement
Are they local stack-variables?? If they are they will cause your stack to overflow and crash your program.

Joakim Asplund
http://megajocke.cjb.net
Joakim Asplundhttp://megajocke.y2.org
what do you mean "local stack" variables? can you explain them.
how do i change the stack size?
Are they declared in a function. If they are and not declared as static they will be allocated on the stack, and the stack is not very big. I think you can change the stack size in the linker.

But for large arrays you would probably want to allocate them dynamically (with malloc, new, calloc or something)

Joakim Asplund
http://megajocke.cjb.net
Joakim Asplundhttp://megajocke.y2.org
thanks.

i will experiment with malloc/calloc and see if i can increase the stack size. do i need to do both or just one?
If you allocate the memory dynamically (with one of those functions)
it won''t be allocated from the stack, so you won''t have to increase
the stack size. And allocating such large arrays on the stack is not
recommended. Just remember to free the memory when you don''t need it
any more.

Joakim Asplund
http://megajocke.cjb.net
Joakim Asplundhttp://megajocke.y2.org

This topic is closed to new replies.

Advertisement