Skip to main content
GameDev.net gamedev.net
🔒 Locked

Pointer question

Started by Metal Typhoon May 22, 2003 at 12:25 PM 1 replies 200+ views
Original Post
Metal Typhoon
Metal Typhoon
i'm trying to create a 1024 x 1024 array of unsigned char .. can someone check if i'm doing it right ?
    
unsigned char** Data;

Data = new unsigned char* [Width];
for (int Make = 0; Make < Width; Make++)
	Data[Make] = new unsigned char [Height];
    
both width and height are 1024.. and if i want to clean up the memory how would i do it ? for (int Clean = 0; Clean < Width; Clean++) delete [] Data[Height]; ?? thx alot [edited by - Metal Typhoon on May 22, 2003 1:29:54 PM]
Metal Typhoon
YoshiN
YoshiN
Yeah, that looks right, except for cleaning up, what you have is correct but don''t forget to delete the original pointer (remember it''s a double pointer), so after the loop just:

delete[] Data;

Also I''m assuming you meant delete[] Data[Clean] not [Height];
-YoshiXGXCX ''99
Metal Typhoon
Metal Typhoon
quote:
Original post by YoshiN
Yeah, that looks right, except for cleaning up, what you have is correct but don''t forget to delete the original pointer (remember it''s a double pointer), so after the loop just:

delete[] Data;

Also I''m assuming you meant delete[] Data[Clean] not [Height];


yes ok i got it.. so it will be this ?

for (int Clean = 0; Clean < Width; Clean++)
delete [] Data[Clean];

delete [] Data;

??
Metal Typhoon

Topic Locked

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

Sign in to reply to this topic.