Thread overview
copy only reference rather duplicate a string in appender!string
Dec 26
Marc
Dec 26
Marc
December 26
I do build a string by coping large parts of diffrent buffers, all those buffers live after the functional call, so rather than duplicate those string I'd like to copy only references to those parts rather duplicate every string. I combined appender!string, assumeUnique() and array slices. Something like this:

> auto buffer = appender!string;
> auto list = cycle(buffers);
> while(bufferIsFilled) {
>   char[] buffer = get_buffer(); // pop a buffer from circular buffer
>   int s = get_buffer_size(x); // determine which part of that buffer we need
>   buffer.put(assumeUnique(buf[0 .. s])); // and here's my question
> }
> return buffer.data;
December 26
of course a totally different approach to solve this is welcome, I came from C/C++/C# worlds so I'm in the process of slowly converting my thinking to the D way (which is new for me, since I'm even unifamiliar with python and such, which got such friendly syntax)
December 26
On Tuesday, 26 December 2017 at 15:37:12 UTC, Marc wrote:
> I do build a string by coping large parts of diffrent buffers, all those buffers live after the functional call, so rather than duplicate those string I'd like to copy only references to those parts rather duplicate every string. I combined appender!string, assumeUnique() and array slices. Something like this:

This depends on whether you have several variables as buffers or an array of buffers.

With several variables: http://dpldocs.info/experimental-docs/std.range.chain.html

With an array, or something else iterable: http://dpldocs.info/experimental-docs/std.algorithm.iteration.joiner.2.html

So you can use:

  chain(buf1, buf2, buf3);

Or:

  myBuffers = [buf1, buf2, buf3];
  joiner(myBuffers);

That produces something string-like. (A rope, but with a poor API.) You can iterate through it as a string, you can output it to a file, etc. You can't pass it to something that expects a string specifically; for instance, you can't return that from `MyClass.toString()`.