Home

werasm wrote:

> On Oct 2, 9:31 am, t <tmt...@Yahoo.com> wrote:
>> The stack container adaptor uses deque as its default underlying
>> sequential container. I don't understand why since we only add
>> elements and remove elements from one side of a stack. Why isn't the
>> default vector instead?
>
> I've actually wondered about this question myself. Especially because
> if one used a vector, dynamic allocations will eventually stop,
> whereas
> "I think" with a deque, allocations/deallocations will continue.

That happens only when the length crosses a blocklength multiple. When you
use a pooling allocator (and the HP/SGI reference implementation of the STL
did), the blocks are not returned to the OS but the allocator keeps them
around for re-use by the container. In that case, reallocation of a block
previously vacated is very cheap.

> Vector seemed more natural for especially a stack, considering that it
> only grows to one side.


Best

Kai-Uwe Bux

previous
next

Re: weakrefs and bound methods
TRying to import files from my folder not pythons lib folder
Re: Best programs written completly in Python
Elementary question on preprocessors and xlw
Re: Regular Expression Grouping
Fundacja Hobbit
Kidprotect
Fundacja Iskierka
Fundacja Sloneczko
Mam Marzenie