resizeable arrays: T[new]
Derek Parnell
derek at psych.ward
Mon Jun 4 04:59:07 PDT 2007
On Mon, 04 Jun 2007 02:33:58 -0700, Walter Bright wrote:
> ... we finally hit on the idea of
> making a resizeable array a different type, say:
>
> T[n] a; // static array
> T[] b; // dynamic array
> T[new] c; // resizeable array
>
> a.length = 6; // error, static array
> b.length = 6; // error, dynamic array is not resizeable
> c.length = 6; // ok
Huh? 'static array' used to mean fixed-size array and 'dynamic array' used
to mean 'variable-length array' ... so a dynamic array is not dynamic
anymore?
So a dynamic array is 'sizeable' but not 'resizable'. In other words, once
its length has been set it can never be changed again? Is that what you are
saying? And is that a compile-time or a run-time check?
If this is what 'resizeable' means for dynamic arrays then nearly all my
dynamic arrays will have to be changed to resizable ones, because I rely on
that feature for lots of things.
What is the point of having dynmaic arrays now? The difference between them
an static arrays is rather small.
> b = c; // ok, implicit conversion of resizeable to dynamic
But hang on, you said that b.length isn't allowed to change? Or did you
mean that it can only change if b.ptr also being updated?
> I think this will entail only very rare changes to user code, but will
> be a big improvement in type safety.
Not so sure about that ... I'll do some analysis and report back.
--
Derek Parnell
Melbourne, Australia
"Justice for David Hicks!"
skype: derek.j.parnell
More information about the Digitalmars-d-announce
mailing list