[rust-dev] problems with adding an element to a ' @' vector.

arkaitzj at gmail.com arkaitzj at gmail.com
Mon Dec 10 15:49:31 PST 2012


Aren't both ~vector and @vector dynamic memory? why can we append to a
~vector but not to a @vector?


--
Arkaitz



On Mon, Dec 10, 2012 at 10:38 PM, Patrick Walton <pwalton at mozilla.com>wrote:

> On 12/10/12 2:34 PM, Peter Ronnquist wrote:
>
>> Hi,
>>
>> I am having problems with adding an element to a '@' vector in rust 0.4.
>>
>> The following works fine with a "~" vector but not with a '@' vector:
>>
>>                          let mut objects_1 : &mut ~[Object] =  &mut ~[];
>>                          let mut objects_2 : &mut @[Object] =  &mut @[];
>>
>>                          objects_1.push(Bat_(bat));
>>                          objects_2.push(Bat_(bat));  // Line 124
>>
>
> Appending to an `@` vector would require copying the entire vector, just
> as with arrays in Java. (We should still probably support `push` on it with
> this performance caveat, but that's the reason why we don't right now.)
>
> If you want to append to a vector, you probably want the `DVec` type, or a
> ~vector.
>
> Patrick
>
> ______________________________**_________________
> Rust-dev mailing list
> Rust-dev at mozilla.org
> https://mail.mozilla.org/**listinfo/rust-dev<https://mail.mozilla.org/listinfo/rust-dev>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20121210/674a258f/attachment.html>


More information about the Rust-dev mailing list