www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Does reserve() preallocate for futher appends too?

reply Jack <jckj33 gmail.com> writes:
isn't clear for me if reserve() does preallocate memory so that 
that operator like arr ~= x can use previously allocate memory by 
reserve() or it's just used in slices like b = arr[x .. y]?
Feb 28
next sibling parent reply Adam D. Ruppe <destructionator gmail.com> writes:
On Monday, 1 March 2021 at 03:07:19 UTC, Jack wrote:
 isn't clear for me if reserve() does preallocate memory so that 
 that operator like arr ~= x can use previously allocate memory 
 by reserve() or it's just used in slices like b = arr[x .. y]?
Slicing never allocates memory. reserve extends the capacity for the ~= operator.
Feb 28
parent Jack <jckj33 gmail.com> writes:
On Monday, 1 March 2021 at 03:12:42 UTC, Adam D. Ruppe wrote:
 On Monday, 1 March 2021 at 03:07:19 UTC, Jack wrote:
 isn't clear for me if reserve() does preallocate memory so 
 that that operator like arr ~= x can use previously allocate 
 memory by reserve() or it's just used in slices like b = arr[x 
 .. y]?
Slicing never allocates memory. reserve extends the capacity for the ~= operator.
thanks
Feb 28
prev sibling parent bachmeier <no spam.net> writes:
On Monday, 1 March 2021 at 03:07:19 UTC, Jack wrote:
 isn't clear for me if reserve() does preallocate memory so that 
 that operator like arr ~= x can use previously allocate memory 
 by reserve() or it's just used in slices like b = arr[x .. y]?
You may potentially find this article of use: https://dlang.org/articles/d-array-article.html
Mar 01