#include "stdafx.h"
#include "stdlib.h"
#include "assert.h"
#include <windows.h>
#include <stdio.h>
#include <list>
#include <algorithm>
using namespace std;
void Delete(char* p)
{
delete p;
}
int _tmain(int argc, _TCHAR* argv[])
{
//포인터 보관
list<char*> g_listL; // 16MByte
list<char*> g_listM; // 1MByte
list<char*> g_listS; // 1~1024byte
//약 2GB미만의 메모리 할당
for (int i=0;i<115;i++)
{
g_listS.push_back(new char[4096]); // 1~8192Byte
g_listL.push_back(new char[1024*1024*16]); // 16MByte
g_listM.push_back(new char[1024*1024]); // 1MByte
}
// 16Mbyte 리스트는 해제
for_each(g_listL.begin(),g_listL.end(),Delete);
int nSizeL = (int)g_listL.size();
g_listL.clear();
// 절반 횟수로 좀던 큰 덩어리 32MByte로 할당
nSizeL = nSizeL /2;
for (int i=0;i<nSizeL;i++)
{
g_listL.push_back(new char[1024*1024*32]);
}
for ( ; ; )
{
}
return 0;
}
1. 하나의 사용자 프로세스가 사용하는 약 2GB 미만의 주소공간을 할당한 후의 모습
2. 할당된것중 16MBye크기들만 해제한후 단편화된 모습 (연속적인 메모리 공간이 없어보인다)
3. 다시 더 큰 32MByte 로 할당시 실패
*!! 단편화가되면!!
- 할당가능한 위치를 찾느라 시간이 상대적으로 더걸린다.
- 여유 메모리가 있음에도 연속적인 공간이없어 할당에 실패한다.
'Basic Programming > C, C++' 카테고리의 다른 글
C++ - 비트맵(bmp) 저장 및 불러오기 (0) | 2016.03.29 |
---|---|
C++ - Windows Keyboard Codes (키보드 코드) (0) | 2016.03.24 |
C++ - 메모리 단편화(Fragmentation)의 해결방법 (0) | 2016.03.21 |
C++ - Frame rate (0) | 2016.03.07 |
C++ - 2차원 배열 동적할당 (0) | 2016.03.04 |