Dynamic Arrays Capacity

Mike Parker aldacron at gmail.com
Thu Jun 2 08:24:51 UTC 2022


On Thursday, 2 June 2022 at 08:14:40 UTC, Mike Parker wrote:

> More specifically, it points to the starting address of the 
> allocated block of memory.

I posted too soon.

Given an instance `ts` of type `T[]`, array accesses essentially 
are this:
```d
ts[0] == *(ts.ptr + 0);
ts[1] == *(ts.ptr + 1);
ts[2] == *(ts.ptr + 2);
```

Since the size of `T` is known, each addition to the pointer adds 
`N * T.sizeof` bytes. If you converted it to a `ubyte` array, 
you'd need to handle that yourself.

And so, `&ts[0]` is the same as `&(*ts.ptr + 0)`, or simply 
`ts.ptr`.


More information about the Digitalmars-d-learn mailing list