Change representation of dynamic arrays?
Oskar Linde
oskar.lindeREM at OVEgmail.com
Fri Oct 19 23:46:44 PDT 2007
Walter Bright wrote:
> Currently, arrays are represented under the hood as:
>
> size_t lengthOfArray;
> void* ptrToStartOfArray;
>
> Which works out reasonably well. The problem is if you want to use array
> types as the basis of iterators, and you want to step through the array.
> There's no escaping it being two operations:
>
> decrement the length
> increment the pointer
This has been nagging me too. Doing a = a[1..$]; has never felt very
efficient. Will there be a different syntax for such idioms?
> What does this break?
>
> 1) Passing dynamic arrays to printf as in:
>
> printf("my string is %*.s\n", str);
I'm glad that breaks. That code was never portable anyway, and has
caused headaches porting D code to other platforms.
> 4) It breaks things like cast(ulong)str, if one was crazy enough to do
> that anyway.
This is something 64-bit D also breaks.
> So, what do you think?
It really shows the power of the property syntax that one can
transparently change the underlying representation like this. I am all
for it (as far as I can see now).
Two related things that have been holding me off D2 are waiting for some
announced code breaking changes that will have quite some impact on how
code is written (not mentioning const):
1. T[new]
- Hopefully T[*] (hint ;) )
- Hopefully a reference type
2. Static arrays becoming value types
- Being able to return them from functions
- No longer having to litter the code with incompatible wrapper structs
Are the ETA for those still far away?
--
Oskar
More information about the Digitalmars-d
mailing list