Jethro wrote:

On Friday, 7 April 2017 at 21:02:33 UTC, ketmar wrote:
Nierjerson wrote:

How to implement trick is this and are you 100% sure it works?

e.g.,

char[] x;

x.length = 65536;
x.length = 0;

this won't work. the moment you did `.length = 0;`, you are returned to point zero.

what you have to do is to maintain "shadow length" yourself, like this:

        x.length = 65536;
        size_t xpos = 0;
        
        void put (const(char)[] s...) {
                foreach (immutable char ch; s) {
                        if (xpos == x.length) x.length += 65536; // or anything
                        x[xpos++] = ch;
                }
        }

thanks, I'll try it... seems like it is basically appender though?

yeah. but the key here is to not use any fancy data structures, it is important. the more intermediaries you have, the less control over copying is left for you. also, no slice assigns too -- it is dangerous, as it can easy go out of control.

Reply via email to