|
Ublas : |
From: Jon Pearce (j.pearce_at_[hidden])
Date: 2005-04-01 05:29:31
Hi Michael,
Thanks for your response
>>I notice that *any* call to internal_resize() in array_adaptor,
>>unbounded_array and shallow_array_adaptor triggers a reallocation, even
>>if the new size is smaller than the old
>>e.g.
>>
>> BOOST_UBLAS_INLINE
>> void resize_internal (size_type size, value_type init, bool
>>preserve = true) {
>> if (size != size_) {
>> pointer data = new value_type [size];
>> ...
>> }
>> }
>>
>>Might there be a benefit in replacing this with "if(size < size_)" in a
>>future version of UBlas? (I think that this is what is done in
>>std::vector<T>::resize())
>>
>>
>
>Interesting. The problem is to implement if(size < size_)" the storage types
>would have to track both the capacity and the size. This would introduce an
>undesirable (if small) overhead in the many cases where such resizes are a
>rarity.
>
>I guess it depends on what semantics users expect. What do people prefer?
>
>
>
Just a few thoughts on this:
* The extra book-keeping is small compared to the cost of typical
matrix/vector operations for all but the smallest arrays
* Cases where very small arrays used are often (IMHO - others may
disagree!) of fixed size (e.g. fixed by physical dimension 2D/3D) and
calls to resize() are not required
* Would be nice to be consistent with Standard Library semantics:
std::vector::resize() needn't trigger a reallocation of storage, and
reserve() is also provided to allow one to exploit a priori knowledge in
the case of frequent resize operations
All the best
jon