Best way to clear dynamic array for reuse
Mathias Lang via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Jul 13 05:33:57 PDT 2016
On Wednesday, 13 July 2016 at 12:05:12 UTC, rikki cattermole
wrote:
> On 13/07/2016 11:59 PM, Miguel L wrote:
>> The options would be:
>>
>> a=[];
>> a.length=0;
>> a=null;
>> ...
>> any other?
>>
>> Can you help me please?
>
> All of those "options" do the same thing, remove all references
> to that data.
No they don't. The first and the third change the pointer, so one
cannot reuse the array.
@Miguel: You want to use
http://dlang.org/phobos/object.html#.assumeSafeAppend
See the example in the doc. To reset your buffer you can
use`buff.length = 0` instead of taking a slice as the example
does.
More information about the Digitalmars-d-learn
mailing list