Archived

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

Coleco

malloc() troubles!!!!!!!!!

Recommended Posts

Ok, here''s the problem. I am trying to allocate some memory. Here is the code:

int *MAP;
unsigned int mapsize;

mapsize = (width * height * layers) * 4;  // this is ok, i checked...contains 960

MAP = (int *)malloc(mapsize * sizeof(int));

 
Now, when I display sizeof(MAP) it *always* returns 4 bytes! No matter what, MAP is always 4 bytes... Anoyone know what I am doing wrong? BTW, I am using Borland C++ Builder if that helps. Thanks! -Coleco

~ c o l ec o ~

Rock the cradle of love! You stupid WANKER! S i g n a l D E V .com --HASBRO SUCKS--

Share this post


Link to post
Share on other sites
try using _msize() (or is it msize()) to get the size of the memory-chunk allocated. This size might be slightly larger than the number of bytes you asked for, depending on alignment issues and whether you''re using the debug heap-alloc functions etc...

Share this post


Link to post
Share on other sites
For malloc() in bcb, this works when I try it:

#define ALLOCATED_SIZE(x) (*(((unsigned int*)x)-1)-6)

The amount you initially specify in malloc seems to be rounded up to the nearest multiple of 4, and at least 8 bytes.

Share this post


Link to post
Share on other sites