Change representation of dynamic arrays?

Jascha Wetzel firstname at mainia.de
Sat Oct 20 04:43:36 PDT 2007


Janice Caron wrote:
> On 10/20/07, Jascha Wetzel <firstname at mainia.de> wrote:
>> Walter Bright wrote:
>>> Janice Caron wrote:
>>>> That said, someone posted that you always allocate an extra byte. If
>>>> that's true, problem solved.
>>> Yes, an extra byte is allocated for just this reason.
>> couldn't the end pointer just point to the last element?
> 
> Oooh yuk. How horrible. I'd rather that didn't happen. For one thing,
> it means that empty arrays (and empty collection ranges generally)
> would have to have a different representation.
> 
> No, I like the "standard" way of doing things, whereby the end
> iterator refences the last+1 element (and therefore cannot be
> dereferenced).

one can argue, that this way, empty arrays have an unambiguous 
representation (they are always null).
there is enough code like
if ( str is null || str == "" )
which wouldn't be necessary.
the current semantics deal with null arrays in the same way as with 
empty arrays (length == 0, appending works alike). therefore, the 
additional expressiveness one would usually expect (empty array vs. 
invalid array) isn't quite there.
but i still wonder, whether there would be performance issues.



More information about the Digitalmars-d mailing list