Skip to main content
gamedev.net
🔒 Locked

Pointer to pointer aka **

Started by yanuart 2 replies 400+ views
Original Post
yanuart
yanuart
Do u think using ** to make an array of pointer is safe ??? Can it cause problems later on ?? Edited by - yanuart on December 31, 2001 10:30:00 AM
Ride the thrill of your life
Play Motorama
Nubbinoski
Nubbinoski
In itself, its fine. Ive used it many times in the past. The hardest part is to make sure your deleting all of the allocated memory. Ive tracked a lot of leaks to poorly maintained arrays of pointers, so much in fact that Ive started using the Standard Template Library to maintain my arrays. It seems to work better for me.

N.
yanuart
yanuart
Well what I wanna do is to make an array of pointer to an object, the array size can be quite huge though.
Using ** is very convinient for me because I don''t have to set up the size of the array and yet I can use array style coding to get my pointer.
Are u sure it''s safe ?? the biggest problem that i worried the most is that i don''t have to set up the size of the array ?? don''t u think it''ll someday ruin everything ??
Ride the thrill of your life
Play Motorama
Nubbinoski
Nubbinoski
How are you adding elements to your array.

If you are tracking a current count and then allocating a new array of old array length + 1, then copying the old array into the new locations for huge amounts of pointers can be very CPU cycle costly and more error prone, but do-able. Again, its just a matter of how you maintain it.

If its a pre-allocated array of pointers its only limited by system resources, and access will be fast.

But if its going to be a large unknown number of elements, I recommend using STL . that way you can constantly add new elements without worrying about memory copying or how big it will be, STL handles it all the dynamic allocation. And with the vector you can still access all your pointers via their index into that array (just slightly different) like this..

Soldier *mySoldier;
mySoldier = SoldierArray.at(5);

Topic Locked

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

Sign in to reply to this topic.