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

Deletion of pointer objects from a map

Hi,

I have a map that stores pointer objects.

I am not able to delete these pointer objects from the map.

For loop that gets each element of the map from begin() to end() and deletes that element does not work.

After insertion of all the elements into the map, the memory increases from 6600 K to 9600K. But after deleting the elements, the memory decreases from 9600 K to 9400 K. There is no other variable or pointer object used inbetween these operations.

Can anyone help me regarding deletion of pointer objects from a map?

Regards,

Yuvanya
Dec 12 '07 #1
3 1521
weaknessforcats
9,208 Expert Mod 8TB
Are you sayinf the objects are not deleted or that they are deleted but the map size has not gone down ???

I suspect the objects are deleted and the map size has not gone down. STL containers once they allocate memory tend to hang on to it so that when you add more elements, the time required to reallocate memory will not be needed. All STL templates are optimized for speed and not for size.

The usual practice here is to create a new map with no elements and then to use the map swap method to swap the two containers.
Dec 12 '07 #2
Thanks a lot. That information was really helpful.

But how do we release the map's memory?

Swapping will be useful if we need to reinitialize the map with some other elements. But what if I just want to clear the memory that the map occupies?

Regards,

Yuvanya
Dec 13 '07 #3
weaknessforcats
9,208 Expert Mod 8TB
You use the swap.

Those STL containers are set up for speed and memory allocating takes time. Therefore, once the container gloms onto memory, it keeps it. For later...
Dec 13 '07 #4

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

Similar topics

2
by: Christopher Pisz | last post by:
currently my node is like so with everything public: class Quadtree_Node { public: Quadtree_Node(Quadtree_Node * parent, Bounding_Box & bounds); ~Quadtree_Node(); void Subdivide(float...
3
by: A_Republican | last post by:
I am interested in writing my own secure file deletion program. I want to be able to read and write to my hard drive directly. My application will seach my hard drive for all locations marked for...
14
by: Ian | last post by:
I am looking at porting code from a C++ application to C#. This requires implementing data sharing functionality similar to what is provided by a smart pointer in C++. I have only recently begun...
1
by: Aff | last post by:
Dear Brothers, i am facing a problem class compactdisc { char title;/string a; int capacity; public:
4
by: lokki | last post by:
Hello, can anybody tell me what's wrong with following example code? char *k, *v; k = new char; strcpy(k, "a2"); v = new char;
2
weaknessforcats
by: weaknessforcats | last post by:
Handle Classes Handle classes, also called Envelope or Cheshire Cat classes, are part of the Bridge design pattern. The objective of the Bridge pattern is to separate the abstraction from the...
4
by: srini4vasan | last post by:
Can we delete 'this' pointer in C++. If so how can we delete this pointer? If not why?
6
by: worlman385 | last post by:
For pointer and non-pointer initialization of an object like MyCar mycar; MyCar* mycar = new MyCar(); I heard from other people saying if object i create must live outside scape, then I use...
5
by: Immortal Nephi | last post by:
I would like to design an object using class. How can this class contain 10 member functions. Put 10 member functions into member function pointer array. One member function uses switch to call...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.