Jump to content
  • Advertisement

Archived

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

Coleco

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

This topic is 6267 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
MAP is a pointer to an int, which has the constant size of 4 bytes. You aren''t doing anything wrong

~~~~~~~~~~
Martee

Share this post


Link to post
Share on other sites
Side note: sizeof() is normally used only with the names of data types (e.g. sizeof(int)), not with variables themselves.

~~~~~~~~~~
Martee

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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!