array slicing policy (and Range implementation)
HOSOKAWA Kenchi
hskwk at inter7.jp
Thu Aug 6 14:24:49 PDT 2009
Tim M Wrote:
> I think Andrei has mostly worked out the fundamentals of ranges and it
> is probably done by treating exisiting views as immutable.
>
> To conclude it works if you can guarantee that you can have all views
> remain valid after any changes to the data block they point too as they
> are not automatically updated.
>
> Also if the compiler sees an update to the length property it will
> insert code to re size the memory block it points too as well as update
> the length property. Apart from this compile time understanding of your
> code, dynamic arrays are interfaced with nothing but a simple struct of
> the length & pointer. This can be wrapped for extra security
> (several implementations already exist) but many like to have the
> maximum performance of it being lightweight.
>
I have once tried to implement some containers to be familiar with Range.
Then I faced the view-validity problem. e.g. discontinuity in doubly-linked list.
I wondered which policy is better, among three models which you pointed out:
* a singleton allocator and immutable views
* wrapped for extra security
* leave it as unsafe but lightweight
I think it is better if we can choose from these, no matter std or third party.
I wish someone (or Andrei) shows us smart implementation of the Range other than array.
More information about the Digitalmars-d
mailing list