Is there a way to clear an OutBuffer?

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun May 22 16:01:07 PDT 2016


On 05/22/2016 11:59 AM, Jon Degenhardt wrote:
> Is there a way to clear an OutBuffer, but without freeing the internally
> managed buffer? Something similar to std.array.appender.clear method.
> Intent would be to reuse the OutBuffer, but without reallocating memory
> for the buffer.
>
> --Jon

Currently not possible. Enhancement request perhaps?

Looking at the implementation, setting its 'offset' member seems to 
work. Based on example from documentation:

import std.outbuffer;

void main() {
     OutBuffer b = new OutBuffer();
     b.writefln("a%sb", 16);
     assert(b.toString() == "a16b\n");

     b.offset = 0;
     b.writefln("a%sb", 16);
     assert(b.toString() == "a16b\n");
}

Bug report perhaps? :)

Ali



More information about the Digitalmars-d-learn mailing list