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

how to clear stl nested map

3
here is a nested stl map

Expand|Select|Wrap|Line Numbers
  1. typedef struct struct_RISCP
  2.     {
  3.  
  4.  
  5.         float nSCPTotal;
  6.         int nSCPCount;
  7.         CString strIMEI;
  8.  
  9.         std::map<UINT8, int> mapSection;
  10.  
  11.  
  12.     }RISCPSt;
  13. map<stRncCellIdntyDmnType, RISCPSt>m_mapRISCP;
it occupied too much memory,i wanted to clear them(both outer map and inner map) ,some one told me you just need to call m_mapRISCP.clear(),then the mapSection (inner map) will be cleared automaticly,in other words, m_mapRISCP.clear() will clear both outer map and inner map,who can tell me is it right, thanks.
May 21 '13 #1
5 3021
Oralloy
988 Expert 512MB
onunix,

You should be good.

Since I can't quote chapter and verse of the C++ specification at you, I looked in my system's include files.

I looked in the STL implementation of map, which is implemented as a red/black tree. Looking at the tree object, I see that the "clear" method is explicity called in its destructor.

Cheers,
Oralloy
May 21 '13 #2
onunix
3
I used visual studio 2010,according to what you say,inner map ( mapSection) 's destruction will be called,then what do the destruction do ? will it clear the memory occupied by the element of mapSection ?
May 21 '13 #3
onunix
3
if the element of mapSection(inner map) is cleared automaticly as the outer map's clear() method is called, It seems that it 's not cleared at once, maybe like java garbage collection, it's cleared later. who can make sure it for me,thanks.
May 21 '13 #4
Oralloy
988 Expert 512MB
onunix,

Do your own work.

The comprehensive way to verify that you are getting the destruction done is to create your own shadow new and delete (malloc and free), and then track the addresses. I've done this in the past, it's a bit of effort, and you will have a great deal of data to dig through, assuming your application processes a lot of memory objects.

Alternately, you can put a destructor in your struct_RISCP object, and verify that you are getting the correct destruction of the map. Better yet, you can force clearing of the contained map, and obviate your question.

Alternately, you might want to look through your visual studio header files and verify that you are actually getting the desired behaviour.

Sorry for being so short, I have a bit of a headache this morning. If you honestly believe that the nested maps are not being cleared, then you will have to do a few experiments - I suggest a small sandbox program, as experimenting in a large project is usually painful.

Another techniques you can use for diagnosing your problem is to sub-class the nested map, and then override the clear method. If it is called, you are in luck.

As for what clear does, it returns the memory comprising the contents of the map's structure to the memory pool - it does not normally erase, or otherwise destroy the content of the memory returned.

Kind Regards,
Oralloy
May 22 '13 #5
Oralloy
988 Expert 512MB
onunix,

By the way - if you really want to destroy the contents of the map's memory, then you have a different sort of problem.

In this case, I do not see any reason to destroy the memory contents - all you have is a map emulating a small, sparse integer array, with integer values.

If you expect all 256 key values (the type is UINT8) to be used, then you may be better off using an array instead of a map.

Oralloy
May 22 '13 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Erik Bongers | last post by:
Hi, Nested classes only seem to be able to access static members of the surrounding class : class SurroundingClass { public: class InnerClass { public:
10
by: nimmi_srivastav | last post by:
Below you will see an example of a nested conditional expression that this colleague of mine loves. He claims that it is more efficient that a multi-level if-else-if structure. Moreover, our...
1
by: Dave Veeneman | last post by:
I have created a collection class derived from CollectionBase that can be nested several layers deep. so my root object has several child objects, each of which has several grandchild objects, and...
17
by: Peter Olcott | last post by:
http://www.tommti-systems.de/go.html?http://www.tommti-systems.de/main-Dateien/reviews/languages/benchmarks.html Why is C# 500% slower than C++ on Nested Loops ??? Will this problem be solved in...
8
by: Portroe | last post by:
I think I have asked this before, :-) but old posts are deleted it seems, How do you clear textboxes in a form, (on submit)? thanks portroe
77
by: Peter Olcott | last post by:
http://www.tommti-systems.de/go.html?http://www.tommti-systems.de/main-Dateien/reviews/languages/benchmarks.html The above link shows that C# is 450% slower on something as simple as a nested loop....
37
by: Tim N. van der Leeuw | last post by:
Hi, The following might be documented somewhere, but it hit me unexpectedly and I couldn't exactly find this in the manual either. Problem is, that I cannot use augmented assignment operators...
5
by: Calvin Spealman | last post by:
On Wed, Aug 13, 2008 at 11:32 AM, Cousson, Benoit <b-cousson@ti.comwrote: There is no point of nested classes because nested classes _are not_ supported by python. They are simply an artifact of...
3
by: Cousson, Benoit | last post by:
I don't think so; my original email was mainly a question. I do agree that they are other ways to do what I'm trying to achieve; there are always several ways to solve an issue. Few days ago, I...
2
bugboy
by: bugboy | last post by:
I'm building an interface like "column view" on a mac. I have nested <div> columns inside another <div> container which is set to 57% width of page. The nested div's act as columns which are...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.