- 论坛徽章:
- 0
|
#include <iostream>
#include <map>
typedef std::map<int, char *> test_map;
typedef std::pair<int, char *> test_pair;
int main()
{
test_map tt_map;
sleep(20);
for(int i=0; i<50; i++)
{
char *str = new char[10];
sprintf(str , "hello");
tt_map.insert(test_pair(i , str));
bzero(str , sizeof(str));
usleep(15000);
std::cout<<"i = "<<i<<std::endl;
}
std::map<int , char *>::iterator its;
for(int i=0; i<50; i++)
{
its = tt_map.find(i);
if(its != tt_map.end())
{
char *str = NULL;
str = its->second;
delete [] str;
str = NULL;
tt_map.erase(its);
usleep(15000);
std::cout<<"i = "<<i<<std::endl;
}
}
sleep(-1);
}
|
用top查看内存,为什么insert前和erase后内存大小不一样....
谢谢..... |
|