www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Is there a way to clear an OutBuffer?

reply Jon Degenhardt <jond noreply.com> writes:
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
parent reply =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
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 22 2016
parent reply Jon Degenhardt <jond noreply.com> writes:
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 22 2016
next sibling parent Seb <seb wilzba.ch> writes:
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 23 2016
prev sibling parent reply Gary Willoughby <dev nomad.so> writes:
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 25 2016
parent Jon Degenhardt <jond noreply.com> writes:
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.
May 25 2016