> Can you tell me how I store my objects, vector or set or individual 
> objects? If I have 10000 objects. Perhaps set is a good way, but it is 
> much different from array.

Depends on how you need to find the objects, and on how dynamic the
set is. If you just create them, and they know how to go away
themselves, and are found at the appropriate times, then individual
objects is the best approach.

If you create all 10000 at one time, and then they live until the end
of the application, and you need to iterate through them, put their
pointers into a vector.

If you have sometimes 5000, sometimes 10000, and you are more
frequently creating than actually using the objects, sets might be
more performant.

> It is different. When I re-allocate my array, I know the address is 
> invalid, I can do something to keep the correct addresses. But in vector,
> when I push_back an element to vector, I do not know the addresses I keeped 
> is valid or not.

I would need to re-read the standard, but I think these things are
specified, and it probably says that you cannot assume that the
addresses remain valid.

> If I can not extend it, I will use array, what is the goodness of 
> vector?

In this particular application, nothing. However, there are good
applications for vectors. They don't involve keeping references to
fields, though.

Regards,
Martin

Reply via email to