On Sat, 25 Apr 2009 19:44:18 -0400, Andrei Alexandrescu <seewebsiteforem...@erdani.org> wrote:
Christopher Wright wrote:
Simple solution: put the array definition in object.d and try implementing arrays with reference counting or manual memory management. I think stored slices break manual memory management, even with a dedicated slice type; but they should work just fine with refcounting. If you don't want to change the language, object.Array will have to implement the logic for slices and for allocated arrays. It's a bit ugly, and it makes the Array type larger. Also, Array's reference count would need to be accessed by reference.

There are three schemes that are good starting points:

1. As right now :o).

2. Using refcounting. Arrays will be 4 words long (begin, end, end-of-store, refcount*) and slices will be 3 words long (begin, end, and owner*)

Or, use (begin, length, store*) for both arrays and slices and have the store contain (start, capacity, refcount).

3. Using manual management. Arrays will be 3 words long (begin, end, end-of-store) and slices will be 2 words long (begin, end). This is close to C++/STL. This case is less safe but very efficient.

Why store end-of-store? It's trivial to compute from the length. (If you have separate slice and array types, that is)

If we manage to integrate them all... that's quite the holy grail. And I think it's entirely possible with only a few changes to the language.


Andrei

Reply via email to