john townsley wrote:
"Noah Roberts" <nr******@dontemailme.com> wrote in message
news:11*************@corp.supernews.com... john townsley wrote:
I want to declare an amount of Objects of Class A to be Global and
to grow in size an amount only known at runtime
std::vector does that. Many other container classes do that. This
is exactly what containers are for.
std::vector< A > global_a_array;
You don't even have to deal with size at all...unless you want to,
then you can give it size to start with, and make it grow when you think
it should.
what about memoery considerations for this, isnt global variables of
Object instances risky
What Karl said.
I will add that using std::vector is a lot safer that doing it by hand.
Really the only memory considerations I can think of is having some
set of functions growing the vector for no reason, or adding copies of
items that are already added by other functions. I think the real way
to deal with that kind of thing, if it is happening, is to use the
Singleton pattern and only allow it to manipulate an internal vector.
Really, depending on the actual needs of the OP, which were not
specific, there are many 'answers' to his problem. Why he is using
globals is something we don't know. It is very possible that a
different approach would be better.