Is it possible to append to a local buffer without reallocating?
Steven Schveighoffer
schveiguy at yahoo.com
Thu Jan 11 18:20:55 UTC 2018
On 1/11/18 12:41 PM, tipdbmp wrote:
>> Appender is able to do this:
>
> It seems that Appender allocates its own private data:
>
> private struct Data
> {
> size_t capacity;
> Unqual!T[] arr;
> bool canExtend = false;
> }
> ....
> private Data* _data;
> ....
> _data = new Data;
>
> But hopefully its bug free unlike what I posted (missing `T.sizeof *` in
> the memcpy call).
>
>
Hm... I thought it was using C malloc, or at least there was a version
where it wasn't allocating an impl struct (I thought that had gone in a
while ago?)
But you can see how to accomplish what you seek by reading the code.
-Steve
More information about the Digitalmars-d-learn
mailing list