Jump to content
  • Advertisement

Archived

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

HPK

Memory problem??

This topic is 5865 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

pls ,can sombody explain to me why when i use this code to assing memory everything hangup . or if doest hungup there it do it when i try to use the array.?? MAPTILE *** Maptiles; Maptiles = (MAPTILE***)malloc(sizeof(int**) * MapLayers); if (Maptiles == NULL) return FALSE; int lyr; int x; for(lyr = 0; lyr < MapLayers; lyr++) { Maptiles[lyr] = (MAPTILE**)malloc(sizeof(int*) * MapWidth); if (Maptiles == NULL) return FALSE; for(x = 0; x < MapWidth; x++) { Maptiles[lyr][x] = (MAPTILE*)malloc(sizeof(int) * MapHeight); } }

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
And what possesed you to create a pointer to a pointer to a pointer?!

Share this post


Link to post
Share on other sites
[screams in horror]

a pointer to a pointer to a pointer - urgh!

I'd stronly suggest using typedef to greatly improve the clarity of that code.

With all the casts and sizeof's for different types going on too my guess is that there's a * too many or too less somewhere causing the wrong level of indirection.

I'd also repeat IndirectX's question about what MAPTILE is to make sure you're allocating the correct sizes for the data.


That code is so unclear that I'd have trouble following it without writing it out and counting stars (I'm too tired anyway - I'm in the GMT timezone - its late )

--
Simon O'Connor
Creative Asylum Ltd
www.creative-asylum.com

[edited by - s1ca on June 30, 2002 10:03:04 PM]

Share this post


Link to post
Share on other sites
look at this and see if you can figure out where u went wrong:


    
int MapLayers = 1;
int MapHeight = 5;
int MapWidth = 5;

MAPTILE *** Maptiles;

Maptiles = (MAPTILE***)malloc(sizeof(int**) * MapLayers);

if (Maptiles == NULL) return FALSE;

for(int lyr = 0; lyr < MapLayers; lyr++)
{
Maptiles[lyr] = (MAPTILE**)malloc(sizeof(int*) * MapWidth);
if (Maptiles[lyr] == NULL) return FALSE;

for(int x = 0; x < MapWidth; x++)
{
Maptiles[lyr][x] = (MAPTILE*)malloc(sizeof(MAPTILE) * MapHeight);
}
}





[edited by - evilcrap on June 30, 2002 10:37:05 PM]

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!