|
Boost : |
From: jhrwalter (walter_at_[hidden])
Date: 2001-12-07 02:40:29
--- In boost_at_y..., Peter Schmitteckert (boost) <boost_at_s...> 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. 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().
Do we really need reserve()? IMO the allocation behaviour of resize()
is a quality of implementation issue, especially since resize() is a
method of the proxy concept. If we intend to make it's behaviour
transparent, we'd have to introduce capacity() first. OTOH capacity()
won't be generic.
BTW, do we need to consider std::allocator?
[snip]
Regards
Joerg
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk