If all that you want is the ability to mutate the elements of the
vector, that should be possible. It may be that the requisite library
support is missing, however, I'm not really certain.
Niko
Sami Nopanen wrote:
Thank you for the answers.
2. How to allocate a mutable managed vector dynamically?
I can create an owned vector with: let a = vec::from_elem(..);
I can create a managed vector with: let a = at_vec::from_elem(..);
You cannot. Because the elements of a managed vector are stored
inline without indirection, and managed vectors are inherently
shared, they cannot change length after they are created. Think of
a managed vector like a Java array, which has the same properties.
If you want a mutable vector, you must place an owned vector into
a managed box. At the moment, this is most conveniently done using
the `DVec` wrapper (this is what it exists for). That is, a type
like `@DVec<T>` is basically the equivalent of Java's `ArrayList<T>`.
In the future, we currently plan to build in better support for
managed, mutable data using a plan, so it is likely that
`@DVec<T>` will be removed in favor of something like `@mut ~[T]`.
I'm finding not being able to store array types in mutable boxes a bit
concerning. Some of my main fields of interest are in computer
graphics and numerical computing, both in which you'd end up having
large arrays of mutable data (frame buffer: mut [u8], matrices: mut
[float]).
And in both cases, the sizes would not be known until runtime, so they
could not be represented as [type * cnt]. In both cases, growing the
vector is of no importance. I guess I could store both in the exchange
heap, but it just seems a bit weird as I don't really have interest
in passing the data between different threads; and I'll lose the
flexibility of being able to have multiple pointers to the data, apart
from using
a wrapper.
_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev