in reply to Re: How to swap scalar values without copies
in thread How to swap scalar values without copies

>> I also suspect that my FETCH method's ${$self->{VRef}} construct is creating a copy.

I definitely think that ${....} creates copies. I set up a shell with virtual memory restricted to a value chosen by me (with ulimit -v ..... This value is such that a small perl program can allocate a large buffer, but not two copies of the buffer. Now, the following code:

$this->{data} = \$large_buffer; print length ${$this->{data}} . "\n";
cannot be executed (it dies of "Out of memory"). So it seems that the reference way (and the function returning the lvalue) are not viable, because the act of dereferencing seems to allocate a copy of the object.

Another indication that the dereferentiation is nasty, is that running a program where I repeatedly dereferentiate a reference to a large buffer is way slower than a program which accesses the buffer directly (orders of magnitude slower than what the dereferentiation overhead per se could justify).

Can you tell me if this is true? or who is eating memory then?