473,405 Members | 2,300 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Deque Item Deletion Problem

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

Apr 1 '06 #1
2 2013
"Sk8Kid" <Sk****@hotmail.com> wrote in message
news:Xn************************@208.49.80.60...
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
Apr 1 '06 #2
"P.J. Plauger" <pj*@dinkumware.com> wrote in news:4c-
dn***************************@giganews.com:
"Sk8Kid" <Sk****@hotmail.com> wrote in message
news:Xn************************@208.49.80.60...
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.


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.
--
Life is complex, with real and imaginary parts.
Apr 8 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Stefan Behnel | last post by:
Hi! In Python 2.4b3, the deque is causing a segfault on two different machines I tested on. With deque, my program runs fine for a while (at least some tens of seconds up to minutes) and then...
16
by: newsock | last post by:
What differences between queue, deque and priority_queue? And under what situations choose one of them to use? Thanks for your help!
19
by: chris | last post by:
Hello, I've recently been trying to understand the various structures supplied by c++, and the one I find most confusing is deque. One quick question about this. It seems most implementations...
9
by: R.Z. | last post by:
i was wondering whether it pays off in terms of memory use to maintain lots of empty deques (it would be convenient for my algorithms but memory use is more important). and does the size of a deque...
2
by: Robbie Hatley | last post by:
I'm getting a strange warning at work when I compile any file in our product that contains a deque of a particular struct. I don't understand this warning, so I'm not sure if this is a Microsoft...
9
by: toton | last post by:
Hi, I am looking for a circular buffer solution ( a fixed buffer) , where the elements can be pushed back & removed front. It looks stl deque can be a solution. my question is, 1) circular...
5
by: yancheng.cheok | last post by:
after reading http://www.codeproject.com/vcpp/stl/vector_vs_deque.asp, i realize that deque has its own speed advantage over vector in all the aspect (except for memory deallocation). does it...
29
by: NvrBst | last post by:
I've read a bit online seeing that two writes are not safe, which I understand, but would 1 thread push()'ing and 1 thread pop()'ing be thread-safe? Basically my situation is the follows: ...
1
Banfa
by: Banfa | last post by:
So the basic sequenced C++ containers are vector - holds data in a contiguous memory block that has the same memory footprint as a classical array. Expensive to insert or delete at the front or...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.