A
Amit Bhatia
hi,
I was wondering how to do the following. I have a class A,
class A{
//;
int a;
//;
};
I wish to instantiate this class, but across all instantiations of the
class, "a" will be given only one of the finitely many values(say 5). As
a result I would like to save memory, and let a bunch of instantiations
share the same copy of "a" and a bunch of other ones another copy and so
on. So "static" won't help here. However, as the number of instances is
huge, this saving might be substantial.I can think of one way to do this:
int &a;
But will this result really in saving any memory? because "a" is just an
integer, and saving just the address will also take some space..Another practical thing to do could be to supply this as an argument in
functions that need it?I have presented a very simplified example above, but in cases where
there are bunch of such integers/doubles etc it becomes important.
thanks,
amit.
--
I was wondering how to do the following. I have a class A,
class A{
//;
int a;
//;
};
I wish to instantiate this class, but across all instantiations of the
class, "a" will be given only one of the finitely many values(say 5). As
a result I would like to save memory, and let a bunch of instantiations
share the same copy of "a" and a bunch of other ones another copy and so
on. So "static" won't help here. However, as the number of instances is
huge, this saving might be substantial.I can think of one way to do this:
int &a;
But will this result really in saving any memory? because "a" is just an
integer, and saving just the address will also take some space..Another practical thing to do could be to supply this as an argument in
functions that need it?I have presented a very simplified example above, but in cases where
there are bunch of such integers/doubles etc it becomes important.
thanks,
amit.
--