Original Post
🔒 Locked
malloc problem
Advertisement
quote:
Original post by matt_j
What is the limit of memory that can be allocated with malloc?
I have 256 MB of ram here, and I am trying to allocate a 524288 byte array, and it crashes.
here is an example:
sz=width*height*4;
GLubyte *tex[50];
tex[2]=(GLubyte *)malloc(sz*sizeof(GLubyte));
There should be no problem at all allocating a 512 kB array. I would expect your problem to be some other reason.
Debug your program:
- what is sz after the first line posted?
- what is tex[2] after the last line you posted?
- if it''s NULL, you have a problem with allocation.
- if your program crashes on this line in debug, you have trashed the memory somewhere else previously, and this has nothing to do with the current malloc call really. In this case, if you''re running on unix, use electric fence or a similar program to track down the actual error. If you''re running on windows, I don''t know. Look through the areas of your code that could be significant and see if you can find the row that writes after/before an allocated array or similar.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement