Boost logo

Boost :

From: Toon Knapen (toon.knapen_at_[hidden])
Date: 2001-12-06 06:26:33


Peter Schmitteckert (boost) wrote:

> Salut,
>
> On Thursday 06 December 2001 10:45, Toon Knapen wrote:
>
>
>>>>For instance if I
>>>>need a temporary matrix in a loop, but in every loop the total size
>>>>of the matrix can be different, I can allocate a matrix with some
>>>>maximal size and resize it in every loop to something smaller in every
>>>>loop in constant amortised time ?
>>>>
>>>Currently not, but it should be possible to change this. May be we
>>>need to differentiate size() and capacity()?
>>>
>>Definitly. This would minimise memory allocation !
>>
>
> I also need this feature to avoid unneccessary allocation,
> but here should be the possiblilty to finally release unneeded memory.
>
> What about the following idea:
> -> resize( n1, n2) garanties "to hold size1 rows of size2 elements".
> -> reserve(n3, n4) garanties that as long n3>=n1, n4 >=n2 no allocations in
> resize(n1,n2) are performed.

I would say that the condition is that n3*n4 >= n1*n2.

> if n3<n1 or n4 < n2 the matrix is allowed to
> shrink to the reserved size if requested in a subsequent resize(..) in
> order to minimize wasted memory.
> But this would lead to the notion of a minimal_capacity().
I don't know if this is a good idea. First it slightly differs from

the vector.reserve call and slight differences from a standard always

lead to subtle bugs. Secondly, if you really want to 'shrink' the matrix,

copy it to another with the desired size. This would need to be done
internally also.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk