T[new]
Stewart Gordon
smjg_1998 at yahoo.com
Sun Aug 9 14:52:51 PDT 2009
Walter Bright wrote:
<snip>
> Under the hood, a T[new] will be a single pointer to a library defined
> type. This library defined type will likely contain three properties:
>
> size_t length;
> T* ptr;
> size_t capacity;
>
> The usual array operations will work on T[new] as well as T[].
<snip>
Would new T[10] allocate this structure and the array data on a single
GC block, or on two separate blocks? And when the array is reallocated,
will the structure move with it?
I suppose it depends on whether you want T[new] to be
(a) something whereby all references persist as the array is reallocated
(b) merely a reference to an allocated array as opposed to an array slice
If (a), this is currently achievable with a T[]*.
If (b), what might work well is a structure like
size_t length;
size_t capacity;
T[capacity] data;
meaning still only one allocation and only one level of indirection when
one is used. And the T[new] variable itself would simply hold &data[0].
Moreover, would whatever happens solve such const/invariant holes as bug
2093?
Stewart.
More information about the Digitalmars-d
mailing list