Cost of .dup vs. instantiation
    Chris via Digitalmars-d-learn 
    digitalmars-d-learn at puremagic.com
       
    Wed May 28 07:36:24 PDT 2014
    
    
  
I use Appender to fill an array. The Appender is a class variable 
and is not instantiated with each function call to save 
instantiation. However, the return value or the function must be 
dup'ed, like so:
Appender!(MyType[]) append;
public auto doSomething() {
   scope (exit) { // clear append }
   // ... do something
   append ~= item;
   return (append.data).dup
}
My question is whether I save anything with Appender as a class 
variable here. I have to .dup the return value (+ clear the 
Appender). If I had a new Appender with each function call, it 
might be just as good.
public auto doSomething() {
   Appender!(MyType[]) append;
   // ....
   return append.data.
}
Right or wrong?
    
    
More information about the Digitalmars-d-learn
mailing list