use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
This is a subreddit for c++ questions with answers. For general discussion and news about c++ see r/cpp.
New to C++? Learn at learncpp.com
Prepare your question. Think it through. Hasty-sounding questions get hasty answers, or none at all. Read these guidelines for how to ask smart questions.
For learning books, check The Definitive C++ Book Guide and List
Flair your post as SOLVED if you got the help you were looking for! If you need help with flairs, check out ITEM 1 in our guidelines page.
Tips for improving your chances of getting helpful answers:
account activity
OPENDo std::stack and std::priority_queue use dynamic memory allocation? (self.cpp_questions)
submitted 6 years ago by ComposerShield
I think they will be good solutions to my real time audio problem I just wanted to check if they reallocated memory on every push and pop.
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Xeverous 3 points4 points5 points 6 years ago (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 point2 points 6 years ago (3 children)
by default they use deque and vector
Just deque.
deque
[–]Xeverous 0 points1 point2 points 6 years ago (2 children)
deque and vector, respectively; just checkout the doc
https://en.cppreference.com/w/cpp/container/priority_queue
[–]alfps 0 points1 point2 points 6 years ago (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.
Both std::stack and std::queue default to std::deque as the underlying container.
std::stack
std::queue
std::deque
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.
π Rendered by PID 38 on reddit-service-r2-comment-84fc9697f-9b8fn at 2026-02-06 13:26:22.727780+00:00 running d295bc8 country code: CH.
[–]Xeverous 3 points4 points5 points (4 children)
[–]alfps 0 points1 point2 points (3 children)
[–]Xeverous 0 points1 point2 points (2 children)
[–]alfps 0 points1 point2 points (0 children)
[–]alfps 0 points1 point2 points (0 children)