473,769 Members | 6,473 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Deletion of pointer objects from a map

2 New Member
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 1539
weaknessforcats
9,208 Recognized Expert Moderator Expert
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
Yuvanya
2 New Member
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 Recognized Expert Moderator Expert
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
1650
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 smallest_node); const Quadtree_Node *& GetTopLeft(); Bounding_Box m_bounds; // Bounding Coordinates of this node
3
1681
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 deletion and then replace it with "x" or something that securely removes previoius data. My question is what objects, API calls, etc, etc do I use to read and write directly to the hard drive? -- Regards, Shaun Goldston
14
18207
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 to work in C# and am asking for suggestions/comments of how to implement a similar data sharing technique in C#. A C++ smart pointer can be used to share common information. For example, assume information managed by objects I1, I2, I3,...
1
1348
by: Aff | last post by:
Dear Brothers, i am facing a problem class compactdisc { char title;/string a; int capacity; public:
4
4124
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
35621
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 implementation so the two can vary independently. Handle classes usually contain a pointer to the object implementation. The Handle object is used rather than the implemented object. This leaves the implemented object free to change without affecting...
4
2214
by: srini4vasan | last post by:
Can we delete 'this' pointer in C++. If so how can we delete this pointer? If not why?
6
2526
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 pointer version, else if only use object for a limited scope, then use non-pointer version. Does limited scope means the object is only used in the same function
5
3653
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 10 member functions. Can switch be replaced to member function pointer array? Please provide me an example of source code to show smart pointer inside class. Thanks....
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10216
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10049
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9997
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9865
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8873
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3565
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.