Assalamu alaikum teman2,
Saya membuat simple code seperti dibawah ini, untuk testing list dan memory
permasalahannya ketika saya deallocate kenapa memorynya nggak mau turun ya.
saya lihat pakai top tetep saja gede. Begitu juga ketika saya ganti std::list dengan
std::vector
tetapi ketika list nya saya ganti dengan array biasa char* p[10000],
memory bisa turun dengan baik.
apakah ada yang salah dengan impelemntasi std::list dan free memory saya.
mohon pencerahannya.
Wassalamu alaikum.
//testx.cpp
#include <stdlib.h>
#include <stdio.h>
#include <list>
typedef std::list<char*> CHAR_LIST;
int main()
{
CHAR_LIST clist;
char c;
printf("enter a to alocate: ");
scanf("%c", &c);
scanf("%c", &c);
for(int i=0; i<10000; i++){
char* p = (char*)malloc(1024);
memset(p, 'x', 1024);
clist.push_back(p);
}
printf("enter d to deallocate: ");
scanf("%c", &c);
scanf("%c", &c);
CHAR_LIST::iterator it;
int n = 0;
for(it = clist.begin(); it != clist.end(); it++){
n++;
free(*it);
}
clist.clear();
printf("enter x to exit: ");
scanf("%c", &c);
scanf("%c", &c);
return EXIT_SUCCESS;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]