On 6/13/12 8:06 PM, Bennie Kloosteman wrote:
In User programs in most cases you would just leave it as dynamic vector ( or better yet some form of collection or enumerable interface depending on whether it will be frequently changed by the user). For hard core systems programming you would often stick to the arrays .
That is my guess as well. Converting to a vector is kind of a "freeze" operation.
What about Java or C# style Array = immutable array ( I would use ArrayValue or ArrayCopy for non ref arrays) Vector or List<T> /ArrayList for dynamic vectors. Note the list name here matches the IList interface .
I wanted a name pattern that extends beyond arrays to strings as well and possibly other data structures. `mvec`, `mstr` works but is quite concise. Something like `vec_builder` and `str_builder` might be good, but is rather long.
Why bother ? ArrayList / StringBuilder just builds an array of space internally and tracks its own capacity which the user can optionally set in a constructor. When they run out of space which the user didn't allow for you just create a new array of double the size. No need for system functions here. However rust doesn't have encapsulation so the internal type being build is accessible , not sure if this is an issue ?
This is ... well, basically what I described, I think? I want to keep the fill/alloc bits but have them be managed by dvec (or whatever it gets called) because that way we can safely leave parts of the vector uninitialized. Then when/if the vector is ultimately "unpacked", we don't have to copy anything.
Would you want single and multi threaded versions of the builders stringbuilder/ArrayList or just a multi threaded one ? Not much time is spend in builders.
Just single-threaded, seeing as Rust has no mutable shared state.
BTW how do you encapsulate the pointer in rust ?
I am not sure what you mean. What I mean by "encapsulate" is just "be sure that it does not escape by careful inspection of the code". That is, `dvec` would be carefully coded so that it always knows whether it has the only pointer to the vector or not (much like StringBuffer in Java). Regions help here because they allow us to give out temporary pointers.
Niko _______________________________________________ Rust-dev mailing list [email protected] https://mail.mozilla.org/listinfo/rust-dev
