Sign in to follow this  
Cornstalks

Deleting Pointer Arrays, but not the whole array

Recommended Posts

Is there a way to delete pointer arrays without deleting the entire array? For example, say you have a pointer array called Array[50]. Now say you don't need Array[35] anymore. Is there away to delete only Array[35]? Well, thanks for reading. --Michael

Share this post


Link to post
Share on other sites
Not without rebuilding the entire array... probably what you're looking for is std::list (the STL linked list classes) in C++ or, java.util.List for java...

Share this post


Link to post
Share on other sites
Quote:
Original post by MikeTacular
Is there a way to delete pointer arrays without deleting the entire array?

For example, say you have a pointer array called Array[50].
Now say you don't need Array[35] anymore. Is there away to delete only Array[35]?

Well, thanks for reading.
--Michael


so


void func()
{

Type *Array[50];

for( int i = 0 ; i < 50 ; i++ )
Array[i] = some_pointer_generator(i);

// ok now we no longer need 35

delete Array[35]; // c++
free( Array[35] ); // c

Array[35] = NULL; // mark it as unused

}



you could optionally move all the elements back so the gap is at the end, but a std::vector would probably be what you want if your going to start doing things like that

Share this post


Link to post
Share on other sites
Well thanks everyone. Sorry, I should have said I was using c++, which I am. I haven't exactly figured out the STL, for a beginner I find it very confusing. I'll try looking at it though.

Share this post


Link to post
Share on other sites
This looks like a job for vectors! as stated before...

it's easy and fun.

vector<your type> name; (or name() if theres a constructor)

then you can do vector.reserve(name.end(), 50 million, type)

or push/pop operations, you can clear the list, whatever you want. its really dynamic. only problem is, making multidimensional vectors is a bit complicated. I was reaidng Dr GUI's article about it on a MSDN archive and i was totally lost :(

[Edited by - AAAP on November 27, 2005 8:43:08 PM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this