Archived

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

matt_j

malloc problem

Recommended Posts

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));

Share this post


Link to post
Share on other sites
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:

  1. what is sz after the first line posted?
  2. what is tex[2] after the last line you posted?
  3. if it''s NULL, you have a problem with allocation.
  4. 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.

Share this post


Link to post
Share on other sites