A couple of questions about arrays and slices

Cecil Ward cecil at cecilward.com
Thu Jun 22 05:20:19 UTC 2023


On Thursday, 22 June 2023 at 01:05:28 UTC, Paul Backus wrote:
> On Thursday, 22 June 2023 at 00:10:19 UTC, Cecil Ward wrote:
>> Is .reserve()’s argument scaled by the entry size after it is 
>> supplied, that is it is quoted in elements or is it in bytes? 
>> I’m not sure whether the runtime has a knowledge of the 
>> element type so maybe it doesn’t know anything about scale 
>> factors, not sure.
>
> length, reserve, and capacity all use the same unit, which is 
> elements.
>
> reserve passes a TypeInfo instance to the runtime so that it 
> knows the size of the elements. You can see the implementation 
> here:
>
> https://github.com/dlang/dmd/blob/v2.104.0/druntime/src/object.d#L3910

Many thanks Paul, I should have found that!


More information about the Digitalmars-d-learn mailing list