a02hansj@NOstudent.SPAMhis.se wrote:[color=blue]
>[color=green]
> > Common sense. To keep three doubles directly in your vector you will
> > need 3*sizeof(double) bytes. To keep them as pointers in your vector
> > you will need at least 3*(sizeof(double) + sizeof(double*)) plus you will
> > have to perform indirection, you will have to make sure the pointers are
> > valid and so on. What do you gain by making them pointers? The size of
> > the vector object itself is less by (3*(sizeof(double)-sizeof(double*)).
> > Is that a smart move? I don't think so.[/color]
>
> Well, what I was thinking might be in favor of making them pointers was
> that they end up on the heap, rather than the stack.[/color]
But the pointers will still be 'on the stack'.
[color=blue]
> And if I have a
> huge honking lot of these little things, I'd rather not fill up the
> stack with that.[/color]
Don't worry, You won't have much of them 'on the stack'.
You can always allocate the whole vector object dynamically.
In general - allocate dynamically if:
* you don't know in advance how many
(which is not the case in your case. You know that your vector
contains exactly 3 doubles)
* you need polymorphism and have a need to polymorphic objects
in a container
(which is not the case. The doubles in that class will stay doubles
for a long time)
* your class is extremely large.
(which is not the case. 3 doubles is *not* large. 300000 would be, but
3 is definitly not)
Otherwise prefer the cleanest and simplest design. And that is: If you want
3 doubles, then make them 3 doubles.
--
Karl Heinz Buchegger
kbuchegg@gascad.at