Dynamic array of strings and appending a zero length array

Cecil Ward cecil at cecilward.com
Sun Jul 9 17:27:13 UTC 2023


On Saturday, 8 July 2023 at 20:01:08 UTC, H. S. Teoh wrote:
> On Sat, Jul 08, 2023 at 05:15:26PM +0000, Cecil Ward via 
> Digitalmars-d-learn wrote:
>> I have a dynamic array of dstrings and I’m spending dstrings 
>> to it. At one point I need to append a zero-length string just 
>> to increase the length of the array by one but I can’t have a 
>> slot containing garbage. I thought about ++arr.length - would 
>> that work, while giving me valid contents to the final slot ?
>
> Unlike C/C++, the D runtime always ensures that things are 
> initialized unless you explicitly tell it not to (via 
> void-initialization). So ++arr.length will work; the new 
> element will be initialized to dstring.init (which is the empty 
> string).
>
>
> T

Many thanks, it might give me a slightly better result just doing 
++arr.length;


More information about the Digitalmars-d-learn mailing list