Deque Item Deletion Problem

S

Sk8Kid

Hi, I have an fairly large std::deque<std::string> object, with
about 100,000 or so strings in it. Calling object.clear() freezes
my application for several seconds, which is undesirable. What
is the best way to reclaim deque memory without freezing my app?
I tried deleting the items one at time with a message pump but I
knew that wouldn't work because deque does caching.

while(!deque_object.empty()) {
deque_object.pop_front(); // doesn't reclaim memory
WindowsMessagePump(); // to keep app responsive
}

Is there a way to make sure a call to pop_front() or erase() will
also reduce both the size and the capacity of the deque? I'm using
MSVC 2005.

Thanks
 
P

P.J. Plauger

Hi, I have an fairly large std::deque<std::string> object, with
about 100,000 or so strings in it. Calling object.clear() freezes
my application for several seconds, which is undesirable. What
is the best way to reclaim deque memory without freezing my app?
I tried deleting the items one at time with a message pump but I
knew that wouldn't work because deque does caching.

No, it doesn't.
while(!deque_object.empty()) {
deque_object.pop_front(); // doesn't reclaim memory
WindowsMessagePump(); // to keep app responsive
}

Is there a way to make sure a call to pop_front() or erase() will
also reduce both the size and the capacity of the deque? I'm using
MSVC 2005.

You're probably seeing the delay within malloc/free in redigesting
the freed storage. Your safest bet is to write an allocator that
sets aside a region for deque allocations, then frees it as a single
block when its last allocator is destroyed.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
 
C

Csaba

No, it doesn't.


You're probably seeing the delay within malloc/free in redigesting
the freed storage.

Also, most malloc/free implementations (used by new/delete) don't return
memory to the system when free is called. They just keep the memory for
themselves to give out to future malloc calls.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top