pointers, assignments, Garbage Collection Oh My?
Maxim Fomin
maxim at maxim-fomin.ru
Wed Jul 10 19:59:32 PDT 2013
On Wednesday, 10 July 2013 at 18:22:24 UTC, Ali Çehreli wrote:
> And to be pedantic, length comes first:
>
> struct Array (T)
> {
> size_t length;
> T* ptr;
> }
>
> Which is actually property-like because assigning to length
> does pretty complex stuff. So the member cannot be named as
> 'length':
>
> struct Array (T)
> {
> size_t length_;
> T* ptr;
> }
>
> Anyway... :)
>
> Ali
To be pedantic dynamic arrays are implemented in D simply as
struct Array
{
size_t length;
void* ptr;
}
and there is no type parametrization since such arrays handling
is opaque for users (in druntime they are treated as void[]).
Parametrization can be useful in user side since performing any
operations with structure above (void*) will lead to errors. But
in user side there is no point in manipulating the structure
directly, as it can be done using usual properties/druntime
without template bloat. By the way, the style ABI page is
written, allows implementation to have more fields.
More information about the Digitalmars-d-learn
mailing list