Skip to main content
gamedev.net
🔒 Locked 🎲 GameMaker

Problems with deallocating void**

Started by gcsaba2 Apr 9, 2005 at 1:20 PM 3 replies 1k views
Original Post
gcsaba2
gcsaba2
Hi, I have a code like this:
void** Data = new (void*)[1];
Data[0] = create_bitmap(400,400);
Then I do random stuff with this bitmap, it works fine, for example if I want to draw it then I just write
draw_sprite(Buffer,(BITMAP*)Data[0],100,100);
At the end of the game, I want to deallocate this whole thing. I do it like this:
destroy_bitmap((BITMAP*)Data[0]);   <-- error occurs here
delete[] Data;
So why does it crash when I use delete_bitmap()? Any ideas? Please no replies like "don't use void**" ;)
Drew_Benton
Drew_Benton
Don't use void** [grin] Ok you using void** is fine, look what I did [smile], but not in the manner you have it. First of all, void* is an unknown size, so the line: void** Data = new (void*)[1]; allocates only 4 bytes of memory for it is a pointer to 'unknown'. That's your main problem. So what you need to do instaed is something like this:

void** Data = new (BITMAP)[1];
// void** Data = new (BITMAP*)[1]; ?? I'm not sure
Data[0] = create_bitmap(400,400);

Now that *should* work. If not please let us know, there is probabally some syntax error somewhere where I posted.

- Drew
gcsaba2
gcsaba2
Wow you COMPLICATE STUFF even more than I do [grin]. In the end I figured out the same thing you said, and decided it's not worth it. Sure I'd save memory space, but writing stuff like (*(int*)Data[4]) = 5; is just not the thing I'd like to write for a long time. I created several separate arrays for int, BITMAP and other types, it all works ok, only it takes up more space and the code is longer... [sad]
PnP Bios
PnP Bios
for the love of all that is holy, avoid using double pointers. No element of game development, outside of tool development, should involve double pointers.
Drew_Benton
Drew_Benton
Good decision [smile] I think void* is pushing it, but two levels of direction, as PnP Bios has said, is really useless in games.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.