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

Started by
3 comments, last by Coleco 22 years, 9 months ago
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--
Rock the cradle of love! You stupid WANKER!
Advertisement
MAP is a pointer to an int, which has the constant size of 4 bytes. You aren''t doing anything wrong

~~~~~~~~~~
Martee
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers
Side note: sizeof() is normally used only with the names of data types (e.g. sizeof(int)), not with variables themselves.

~~~~~~~~~~
Martee
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers
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...
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.

This topic is closed to new replies.

Advertisement