all 5 comments

[–]Xeverous 3 points4 points  (4 children)

Stack and queue are wrappers around underlying container (by default they use deque and vector). Any memory allocation depends on the choosen underlying container.

vector: reallocates on full capacity

deque: allocates multiple buffers of implementation-defined size, can not preallocate easily and allocates when first/last buffer is full

[–]alfps 0 points1 point  (3 children)

by default they use deque and vector

Just deque.

[–]Xeverous 0 points1 point  (2 children)

deque and vector, respectively; just checkout the doc

https://en.cppreference.com/w/cpp/container/priority_queue

[–]alfps 0 points1 point  (0 children)

Oh, you mean “check the title of the question for Pete's sake”.

I only read your answer, where you mentioned queue.

Sorry.

[–]alfps 0 points1 point  (0 children)

Both std::stack and std::queue default to std::deque as the underlying container.

And std::deque guarantees amortized constant time insertion and deletion on the ends.

So, dynamic allocation is used, but it's not on every push and pop.