On 11/23/2015 04:03 PM, Steven Schveighoffer wrote:
> On 11/23/15 4:29 PM, Jon D wrote:

>> In the example I gave, what I was really wondering was if there is a
>> difference between allocating with 'new' or with 'reserve', or with
>> 'length', for that matter. That is, is there a material difference
>> between:
>>
>>      auto x = new int[](n);
>>      int[] y; y.length = n;
>
> There is no difference at all, other than the function that is called
> (the former will call an allocation function, the latter will call a
> length setting function, which then will determine if more data is
> needed, and finding it is, call the allocation function).

Although Jon's example above does not compare reserve, I have to ask: How about non-trivial types? Both cases above would set all elements to .init, right? So, I think reserve would be faster if copy() knew how to take advantage of capacity. It could emplace elements instead of copying, no?

Ali

Reply via email to