Is there a way to clear an OutBuffer?

Jon Degenhardt via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun May 22 20:03:12 PDT 2016


On Sunday, 22 May 2016 at 23:01:07 UTC, Ali Çehreli wrote:
> 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

Thanks. Enhancement request: 
https://issues.dlang.org/show_bug.cgi?id=16062


More information about the Digitalmars-d-learn mailing list