Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
May 22, 2016 Is there a way to clear an OutBuffer? | ||||
---|---|---|---|---|
| ||||
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 |
May 22, 2016 Re: Is there a way to clear an OutBuffer? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jon Degenhardt | 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
|
May 23, 2016 Re: Is there a way to clear an OutBuffer? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ali Çehreli | 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 |
May 23, 2016 Re: Is there a way to clear an OutBuffer? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jon Degenhardt | On Monday, 23 May 2016 at 03:03:12 UTC, Jon Degenhardt wrote: > On Sunday, 22 May 2016 at 23:01:07 UTC, Ali Çehreli wrote: >> On 05/22/2016 11:59 AM, Jon Degenhardt wrote: >>> [...] >> >> 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 It was once proposed to have start & stop, which could also imply that it's resettable: https://github.com/dlang/phobos/pull/3362 |
May 25, 2016 Re: Is there a way to clear an OutBuffer? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jon Degenhardt | On Monday, 23 May 2016 at 03:03:12 UTC, Jon Degenhardt wrote:
>> 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
Is there a consensus on this? Does this really need a clear method seeing as though you can reset the offset directly?
|
May 26, 2016 Re: Is there a way to clear an OutBuffer? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Gary Willoughby | On Wednesday, 25 May 2016 at 19:42:43 UTC, Gary Willoughby wrote:
> On Monday, 23 May 2016 at 03:03:12 UTC, Jon Degenhardt wrote:
>>> 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
>
> Is there a consensus on this? Does this really need a clear method seeing as though you can reset the offset directly?
As an end-user, I'd have more confidence using a documented mechanism. If it's setting a public member variable, fine, if it's a method, also fine.
The 'offset' member is not part of the publicly documented API. Looking at the implementation, it doesn't appear 'offset' is intended to be part of the API. Personally, I'd add a method to keep 'offset' out of the public API. However, simply documenting it is an option as well.
|
Copyright © 1999-2021 by the D Language Foundation