|
![](/i/fill.gif) |
Hmm, so vectors seem to be able to do some pretty death-defying stuff!
They're variable size, but they manage their memory automatically.
Now in a GC language, you can just pass anything anywhere. Usually in a
language with manual memory management you have to be extremely careful
about doing that.
However, vectors seem to make this surprisingly safe. Indeed, it appears
that you can pass a vector in any way that you could pass something like
an integer, and it will just do The Right Thing(tm). The only difference
is that throwing a large vector around by value probably isn't a good idea.
Is that about right?
Here's another question: Suppose you have a function that's supposed to
create a new vector and return it to the caller. What's the best way to
do that?
Obviously the ideal thing to do would be to return a reference. However,
if I create a vector in an auto variable, presumably when the function
returns that variable will vanish, making the reference to it unusable.
(If I'm understanding how this works.)
I guess if I return it by value the problem goes away. But that doesn't
seem terribly efficient.
Maybe the thing to do would be to have the caller pass in a reference to
an empty vector created outside?
Just trying to get my head round this stuff so I don't do anything dumb...
Post a reply to this message
|
![](/i/fill.gif) |