- ¸Þ¸ð¸® ÇÒ´ç
- 2°³ ÀÌ»óÀÇ ÈüÀ» »ç¿ëÇÑ ¸Þ¸ð¸® ´ÜÆíÈ ÇØ°á ¹æ¾È
- Multi-Processor Heap
- Windowx XP Low-fragmentation Heap
- ¸µÅ©
1 ¸Þ¸ð¸® ÇÒ´ç
¸Þ¸ð¸® ÇÒ´ç¿¡ ÀÖ¾î¼, À̽´´Â 2°¡Áö¶ó°í º¼ ¼ö ÀÖ´Ù. ù¹øÂ°´Â ½º·¹µå Á÷·ÄÈ¿¡ µû¸¥ ¼º´É ÀúÇÏ, µÎ¹øÂ°´Â ´ë·®ÀÇ ÇÒ´ç/ÇØÁ¦¿¡ µû¸¥ ´ÜÆíÈÀÌ´Ù. ¼º´É ÀúÇϸ¦ ÇÇÇÏ¸é¼ ´ÜÆíȸ¦ ÃÖ¼ÒÈÇÏ´Â °ÍÀÌ ´ëºÎºÐÀÇ ¹ü¿ë ¸Þ¸ð¸® ÇÒ´ç ¾Ë°í¸®ÁòµéÀÌ Ãß±¸ÇÏ´Â ¹ÙÀÌ´Ù.
2 2°³ ÀÌ»óÀÇ ÈüÀ» »ç¿ëÇÑ ¸Þ¸ð¸® ´ÜÆíÈ ÇØ°á ¹æ¾È
from
Unmanaged Memory Fragmentation -- an old story
¿ä¾àÇØº¸ÀÚ¸é...
2°³ÀÇ ÈüÀ» ÇÒ´çÇÑ ´ÙÀ½ N¹øÂ°, ¿¹¸¦ µé¾î 100000¹øÂ°±îÁö´Â ù¹øÂ° Èü¿¡¼ °è¼Ó ÇÒ´çÀ» Çϰí, 100001¹øÂ°ºÎÅÍ´Â µÎ¹øÂ° Èü¿¡¼ ÇÒ´çÀ» ÇÑ´Ù. ±×·¯´Ù 200000¹øÂ° ÇÒ´çÀÌ ÇÊ¿äÇÏ°Ô µÇ¸é ´Ù½Ã ù¹øÂ° Èü¿¡¼ºÎÅÍ ÇÒ´çÀ» ÇÑ´Ù.
static size_t g_Allocs = 0;
static int g_HeapIndex = 0;
static HANDLE g_Heap[2] = { NULL, NULL };
...
void* operator new (size_t size)
{
if ((++g_Allocs % 100000) == 0)
g_HeapIndex ^= 0x10;
return ::HeapAlloc(g_Heap[HeapIndex], HEAP_ZERO_MEMORY, size);
} ´ëÃæ ÀÌ·± ½Ä?
ÀÌ¿Í °°Àº ¹æ¹ýÀ¸·Î ¸Þ¸ð¸® ÇÒ´çÀ» ÇÏ°Ô µÇ¸é ÇÑÂÊ¿¡¼´Â ÇҴ縸ÀÌ ÀϾ°í, ³ª¸ÓÁö ÇÑÂÊ¿¡¼´Â ÇØÁ¦¸¸ÀÌ ÀϾ°Ô µÈ´Ù. ´Ù¸¥ ÂÊÀÇ Èü¿¡¼ ÇÒ´çÀ» ÇÏ°Ô µÉ ¶§Âë µÇ¸é, ±× ÈüÀº °ÅÀÇ ±ú²ýÇÑ »óŰ¡ µÈ´Ù´Â ¸»ÀÌ´Ù.
¹°·Ð ¾ÖÇø®ÄÉÀ̼ÇÀÇ Æ¯¼º¿¡ µû¶ó ´Þ¶óÁö±â´Â ÇϰÚÀ¸³ª, Èü¿¡ ¿Ã¶ó°¡´Â µ¥ÀÌÅ͵éÀÌ ±Ý¹æ »ç¶óÁö´Â µ¥ÀÌÅͶó´Â Á¡À» °¨¾ÈÇÏ¸é ±¦ÂúÀ» °Í °°±âµµ ÇÏ´Ù. Àå±â°£ Èü¿¡ Á¸ÀçÇÏ´Â µ¥ÀÌÅÍÀÇ °æ¿ì(·è¾÷Å×ÀÌºí °°Àº...)¿¡´Â µû·Î ÈüÀ» ¸¶·ÃÇØµÎ¸é ±×¸¸. ¹®Á¦´Â Àú 100000À̶ó´Â ¼ýÀÚ¸¦ ¾î¶»°Ô Á¤ÇÏ´À³ÄÀε¥... Èü¿¡ ¿Ã¶ó°¡´Â µ¥ÀÌÅÍÀÇ Æò±Õ ¼ö¸í°ú ÃÊ´ç ÇÒ´ç È£Ãâ Ƚ¼ö¸¦ ¾Ë¾Æ³»¾ßÇϳª?
3 Multi-Processor Heap
Visual C++ 6.0 »ùÇÿ¡ ÀÖ´ø ¼Ò½º·Î¼, ¸ÖƼ ÇÁ·Î¼¼¼ ¸Ó½Å¿¡¼ µ¹¾Æ°¡´Â ¸ÖƼ ½º·¹µå ÇÁ·Î±×·¥ÀÇ ¼º´É °³¼±À» À§ÇÑ ¸Þ¸ð¸® ÇÒ´ç ¾Ë°í¸®ÁòÀÌ´Ù. Visual C++ 6.0 »ùÇÃÀº
¿©±â¿¡¼ ´Ù¿î·Îµå¹ÞÀ» ¼ö ÀÖ´Ù. ¼Ò½º ¿ø¹®¿¡ ÀÖ´ø ³»¿ëÀ» ÀϺΠ¿Å°Üº¸ÀÚ¸é ´ÙÀ½°ú °°´Ù.
Many multithreaded applications that use the standard memory allocation routines (malloc/free, LocalAlloc/LocalFree, HeapAlloc/HeapFree) suffer a significant performance penalty when running on a/ multi-processor machine. This is due to the serialization used by the default heap package. On a multiprocessor machine, more than one thread may simultaneously try to allocate memory. One thread will block on the critical section guarding the heap. The other thread must then signal the critical section when it is finished to unblock the waiting thread. The additional codepath of blocking and signalling adds significant overhead to the frequent memory allocation path.
By providing multiple heaps, this DLL allows simultaneous operations on each heap. A thread on processor 0 can allocate memory from one heap at the same time that a thread on processor 1 is allocating from a different heap. The additional overhead in this DLL is compensated by drastically reducing the number of times a thread must wait for heap access.
4 Windowx XP Low-fragmentation Heap
#include <windows.h>
#include <stdio.h>
void main()
{
ULONG HeapFragValue = 2;
if(HeapSetInformation(GetProcessHeap(),
HeapCompatibilityInformation,
&HeapFragValue,
sizeof(HeapFragValue))
)
{
printf("Success!\n");
}
else printf ("Failure (%d)\n", GetLastError());
} API Çѹø È£ÃâÇØÁÖ¸é ¶¯ÀÌ´Ï, º°´Ù¸¥ ¼ö°í ¾øÀÌ ´ÜÆíȸ¦ ÁÙÀÏ ¼ö ÀÖ´Â ¼ÀÀÌ´Ù. ±×·¯³ª ¼¼»ó ¸¸»ç ±×¸® ½¬¿ï ¸® ¾ø´Ù. ÀÌ ±â´ÉÀº ÇØ´ç Èü¿¡ HEAP_NO_SERIALIZE °°Àº Ç÷¡±×µéÀÌ ÄÑÁ® ÀÖ´Â °æ¿ì¿¡´Â µ¿ÀÛÇÏÁö ¾Ê´Â´Ù. µð¹ö±× ¹öÀüÀÏ ¶§µµ ¾È µ¹¾Æ°¡´Â ¸ð¾çÀÌ´Ù. »ç¿ëÇÒ ÀÏÀÌ ÀÖ±â´Â ÇÒÁö Àǹ®ÀÌ´Ù.
5 ¸µÅ©
-
the HOARD memory allocator
The Hoard memory allocator is a fast, scalable, and memory-efficient memory allocator. It runs on a variety of platforms, including Linux, Solaris, and Windows. Hoard is a drop-in replacement for malloc() that can dramatically improve application performance, especially for multithreaded programs running on multiprocessors. No change to your source is necessary. Just link it in or set just one environment variable.
-
http://g.oswego.edu/dl/html/malloc.html
-
Real-Time Dynamic Memory Allocation
This is a web site dedicated to explicit dynamic storage allocation in the area of real-time systems. Although dynamic storage allocation is a deeply studied subject in computer science, it has not been widely used in real-time systems due to the commonly accepted idea that it is, due to the intrinsic nature of the problem, difficult or even impossible to design a efficient time-bounded algorithm.
-
Gamasutra > Play by Play : Effective Memory Management
¸Þ¸ð¸® °ü¸®ÀÚ¸¦ Á÷Á¢ Á¦ÀÛÇÒ ¶§ »ý°¢ÇؾßÇÒ ¹®Á¦Á¡µé
-
Inside memory management
The choices, tradeoffs, and implementations of dynamic allocation. (Linux)
-
Policy-Based Memory Allocation
SeriousMoin v1 (koMoinMoin 1.0a4 Modified)