A couple of questions about arrays and slices

Cecil Ward cecil at cecilward.com
Wed Jun 21 02:09:26 UTC 2023


First is an easy one:

1.) I have a large array and a sub-slice which I want to set up 
to be pointing into a sub-range of it. What do I write if I know 
the start and end indices ? Concerned about an off-by-one error, 
I have start_index and past_end_index (exclusive).

2.) I have a dynamic array and I wish to preinitialise its alloc 
cell to be a certain large size so that I don’t need to 
reallocate often initially. I tell myself that I can set the 
.length property. Is that true?

2a.) And what happens when the cell is extended, is the remainder 
zero-filled or remaining full of garbage, or is the size of the 
alloc cell something separate from the dynamic array’s knowledge 
of the number of valid elements in it ?


More information about the Digitalmars-d-learn mailing list