Boost logo

Boost :

From: Pavel Vozenilek (pavel_vozenilek_at_[hidden])
Date: 2006-12-17 00:03:40


"Ion Gaztañaga" wrote:

> > One solution may be to provide list::size()
> > and have the size itself encoded as a signed integer.
> > If the integer is >= 0 then the size() will return it.
>
>
> This can be an option. The downside is that size() is a const function
> and we should declare the size member as mutable. This converts a
> thread-safe function like size() to a non-thread safe one.
>

I don't think much of MT safety is obtained by
just relying on atomic list::size(), at least I hope
people don't rely on it.

> To avoid wasting a bit of the internal
> size integer, we could define size() as "this->size_ - 1", so
> this->size_ == 0 could represent unknown size and this->size_== 1 an
> empty list, this->size_ == 2 a list with just 1 element and so on.
>

Using negative value to indicate the need for recalculation
translates into a single assembler instruction (jz on x86).

resize() and empty() would need to do the check as well.

/Pavel


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