- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- how to free memory in vector
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-16-2005 02:05 PM
тАО06-16-2005 02:05 PM
how to free memory in vector
While I used STL in my appliaction, i got a trouble to free the memory.
My test program looks like this:
void f()
{
vector
cout << "push back begin..." << endl;
for ( int i = 0; i < MAXNUM; ++i)
{
b.push_back(i);
}
cout << "push back end..." << endl;
cout << b.size() << ":" << b.capacity() << endl;
b.clear();
cout << "cleared ..." << endl;
cout << b.size() << ":" << b.capacity() << endl;
vector
cout << "swaped ..." << endl;
cout << b.size() << ":" << b.capacity() << endl;
getchar();
}
%aCC -AA testmem.cpp -o testmem
%testmem
push back begin...
push back end...
10000000:10570698
cleared ...
0:10570698
swaped ...
0:0
The matter is that the memory still is 100M after swaped the vecotr, even the variable 'b' went out of its life cycle. It seemd that the memory would never be freeed.
Can any one help me to resolve the problem? Your help is appreciated. Thanks a lot.
Regards,
xbin999
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-29-2005 08:06 AM
тАО06-29-2005 08:06 AM
Re: how to free memory in vector
The same situation happens with STL vector. The only true solution will be to use your own allocator for STL classes.
Other solutions are not so good, and may work or not work.
1. b.resize(0);
2. vector
P.S. The behavior you see is the correct one, and defined by the STL standards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-29-2005 08:34 AM
тАО06-29-2005 08:34 AM
Re: how to free memory in vector
There is a method to shrink the memory usage using the sbrk() system call with a negative increment but if you use that mechanism then you must take sole responsibilty for memory management --- meaning no new, delete, malloc, free --- and none of these in any library code as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-07-2005 02:34 PM
тАО07-07-2005 02:34 PM
Re: how to free memory in vector
The program is ok on the Windows platform, but get trouble on HPUX.
Maybe I need to manage the memory by myself, not STL. But any good suggestions?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-07-2005 04:06 PM
тАО07-07-2005 04:06 PM
Re: how to free memory in vector
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-07-2005 06:32 PM
тАО07-07-2005 06:32 PM
Re: how to free memory in vector
But it's very slow.
Also, the question that arises is: have you checked, that the memory is exhausting, or you just do suppose that?
In addition, swapping with anonymous vector should be in a separate block, to give the compiler hint to destroy the vector immediately.