On 2012-04-08 17:14:37 +0000, Andrei Alexandrescu
<seewebsiteforem...@erdani.org> said:
On 4/8/12 12:05 PM, Walter Bright wrote:
On 4/8/2012 7:53 AM, Andrei Alexandrescu wrote:
Once anyone asks for .ptr a conservative copy will be made.
That could get expensive. You cannot just point into the small string
part, because that may only exist temporarily on the stack. There are
some pathological cases for this.
As I mentioned, the first call to .ptr changes representation, thus
making the allocation that the optimization had saved. Things are not
worse off than before.
This only works if the code has write access to that variable.
Also, if the variable is a temporary copy such as a by-value function
parameter, only the representation of that temporary copy will be
affected. Every time you call a function which calls .ptr a new copy
will be allocated on the heap. If such a function call is part of a
loop, it'll degrade performance noticeably.
--
Michel Fortin
michel.for...@michelf.com
http://michelf.com/