473,402 Members | 2,072 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,402 software developers and data experts.

STL map Unusual behaviour

Hi,

I am using two STL maps as data member for COM server with
VC++6.0.These two maps are unrelated in the sense that they are storing

different data.
first map is of type(6 MB in size)
std::map<long,ISumInfo*>
and second is of type(3 MB in process)
std::map<string,list<string> >
I want to clear the first map but on clearing the map the memory
doesn't come down for process.But as soon as I clear the second map the

memory comes down is equivalent
to size of both the maps.
I am not able to understand that how two maps are related.
For clearing the first map I have released the IsumInfo objects and
destructors are getting invoked properly for clearing the map I have
tried calling
three ways but the result is same.
//m_siteDB.clear();
//m_siteDB.erase(m_siteDB.begin(), m_siteDB.end());
//std::map<long,ISumInfo*>().swap(m_siteDB);
If somebody have faced this issue,Please let me know
Thanx
Sumit

Feb 16 '06 #1
3 2226
sl*****@yodlee.com wrote:
Hi,

I am using two STL maps as data member for COM server with
VC++6.0.These two maps are unrelated in the sense that they are storing

different data.
first map is of type(6 MB in size)
std::map<long,ISumInfo*>
and second is of type(3 MB in process)
std::map<string,list<string> >
I want to clear the first map but on clearing the map the memory
doesn't come down for process.But as soon as I clear the second map the

memory comes down is equivalent
to size of both the maps.
I am not able to understand that how two maps are related.
For clearing the first map I have released the IsumInfo objects and
destructors are getting invoked properly for clearing the map I have
tried calling
three ways but the result is same.
//m_siteDB.clear();
//m_siteDB.erase(m_siteDB.begin(), m_siteDB.end());
//std::map<long,ISumInfo*>().swap(m_siteDB);
If somebody have faced this issue,Please let me know
Thanx
Sumit


The STL containers have built in memory management which reserve memory
for later use. Unless you write your own Allocator the results you are
getting will depend on the STL implementation. It would seem in your
case it's reserved memory for std::map<> use and doesn't immediately
free it up. This helps speed up creating and destroying new map objects
because fewer memory allocation and deallocation calls are required for
these operations.

NOTE!!! Make sure std::map<long,ISumInfo*> pointer within the map object
will not leave memory hanging before destroying the object.

JB
Feb 16 '06 #2
Using STL map,list with own customized Allocator really worked it
reduces the memory
immediately.I have downloaded the allocator from web only.

http://www.codeproject.com/vcpp/stl/...asp#xx159315xx

I have put lot of hours in this to find out the reason but ur reply
really
helped me in rectifying this problem.

Just in case u can know that how good is the above allocator
implementation
let me know.

Thanx,
Sumit

Feb 17 '06 #3
According to Meyer's Effective STL, you can trim excess capacity in
an STL container by using the swap trick.

// define vector fo MyType
vector <MyType> v;

// add elements to v

// create a temporary vector via the copy constructor then swap it with
// v. the copy constructor sizes the temp vector for the "correct"
// amount of memory (not any excess capacity that may be in v).
vector <MyType> (v).swap (v);

// same thing but clears _and_ minimizes capacity.
vector <MyType> ().swap (v);

The book explains this in more depth including what "correct" is and
how it depends on the STL implementation.

You may want to try that since using a customized Allocator seems like
a bit much to accomplish what you want.

sl*****@yodlee.com wrote:
Using STL map,list with own customized Allocator really worked it
reduces the memory
immediately.I have downloaded the allocator from web only.

http://www.codeproject.com/vcpp/stl/...asp#xx159315xx

I have put lot of hours in this to find out the reason but ur reply
really
helped me in rectifying this problem.

Just in case u can know that how good is the above allocator
implementation
let me know.

Thanx,
Sumit


Feb 17 '06 #4

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

Similar topics

11
by: Karlo Basic | last post by:
Greetings! I'm wondering how do the expressions in the following piece of code evaluate and why: #include <iostream> using namespace std; int main() { int n = 5, p;
2
by: Lenster | last post by:
When using PostMessage to post myself a message, the msg and wparam parameters somehow get swapped over. They are in the correct order when calling PostMessage but by the time wndproc handles the...
14
by: Rowland Shaw | last post by:
I've got a databound combo (databound to a System.Data.DataTable), but some rather unpredicatable behaviour -- even though I have 8 rows in the source table, only the first 6 are showing up in the...
5
by: Tino Lange | last post by:
Hi! I'm trying to use the csv Parser included with Python. Field Delimiter is "|", Line Delimiter is "#". Unfortunately it doesn't work as expected. The parser seems to just ignore the...
15
by: John Howie | last post by:
I've found very unusual behavious when using sessions on two different servers. I'm using sessions to handle simple log in. When the form submits the values are checked against a MySQL table. If...
7
by: Rithish | last post by:
Hello. I noticed a strange thing while using strtotime() and date() functions in combination to generate from MySQL into a readable format. By default, the MySQL date field will be 0000-00-00...
7
by: William S Fulton | last post by:
I'm looking for the name of the following casting style in order to do some reading around on it and why it is sometimes used. unsigned long long ull = 0; void * ptr = 0; ull = *(unsigned...
0
by: mk | last post by:
http://linux.byexamples.com/archives/365/python-convey-the-exception-traceba That's seriously weird. What's your Python version and platform? On my Windows and Linux machines, with more recent...
0
by: Robert Rawlins | last post by:
That's seriously weird. What's your Python version and platform? On my Thanks for that MK. I'm using Debian with Python 2.5 from the stable apt repository, installed but a couple of days ago....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.