program tip

기억과 관련하여 경기장이라는 용어의 의미는 무엇입니까?

radiobox 2020. 9. 8. 07:51
반응형

기억과 관련하여 경기장이라는 용어의 의미는 무엇입니까?


프로그래밍 개념으로 기억에 관한 책을 읽고 있습니다. 이후 장 중 하나에서 저자는 arena 라는 단어를 많이 사용 하지만 정의하지는 않습니다. 나는 그 단어의 의미와 그것이 기억과 어떤 관련이 있는지 검색했지만 아무것도 찾지 못했습니다. 저자가 용어를 사용하는 몇 가지 컨텍스트는 다음과 같습니다.

"다음 직렬화 예에서는 특정 분야의 메모리 할당이라는 전략을 통합합니다 ."

"... 이것은 메모리 누수를 처리하거나 특정 분야 에서 할당 할 때 유용합니다 ."

"... 메모리 할당을 해제하려면 전체 경기장 을 할당 해제합니다 ."

저자는 한 장에서이 용어를 100 번 이상 사용합니다. 용어집의 유일한 정의는 다음과 같습니다.

아레나에서 할당 -아레나를 먼저 할당 한 다음 프로그램 자체가 아레나 내에서 할당 / 할당 해제를 관리하는 기술 (이후 프로세스 메모리 관리자가 아님) 복잡한 데이터 구조 및 개체의 압축 및 직렬화에 사용되거나 안전에 중요한 시스템 및 / 또는 내결함성 시스템의 메모리 관리에 사용됩니다.

누구든지 이러한 맥락에서 나를 위해 경기장정의 할 수 있습니까 ?


아레나는 한 번 할당 한 다음 해당 메모리의 일부를 나누어 메모리를 수동으로 관리하는 데 사용하는 크고 연속적인 메모리 조각입니다. 예를 들면 :

char * arena = malloc(HUGE_NUMBER);

unsigned int current = 0;

void * my_malloc(size_t n) { current += n; return arena + current - n; }

요점은 메모리 할당이 작동하는 방식을 완전히 제어 할 수 있다는 것입니다. 제어 할 수없는 유일한 것은 초기 할당에 대한 단일 라이브러리 호출입니다.

한 가지 인기있는 사용 사례는 각 경기장이 하나의 고정 된 크기의 메모리 블록을 할당하는 데만 사용되는 경우입니다. 이 경우 매우 효율적인 교정 알고리즘을 작성할 수 있습니다. 또 다른 사용 사례는 "작업"당 하나의 경기장을 갖는 것입니다. 작업이 끝나면 전체 경기장을 한 번에 해제 할 수 있으며 개별 할당 해제 추적에 대해 걱정할 필요가 없습니다.

각 기술은 매우 전문적이며 일반적으로 수행중인 작업과 일반 라이브러리 할당이 충분하지 않은 이유를 정확히 알고있는 경우에만 유용합니다. 좋은 메모리 할당자는 이미 많은 마법 자체를 수행 할 것이며 메모리를 직접 처리하기 시작하기 전에 충분하지 않다는 상당한 양의 증거가 필요합니다.


나는 가능한 대답 으로 이것으로 갈 것입니다.

•Memory Arena (also known as break space)--the area where dynamic runtime memory is stored. The memory arena consists of the heap and unused memory. The heap is where all user-allocated memory is located. The heap grows up from a lower memory address to a higher memory address.

위키 백과의 동의어 인 region, zone, arena, area, memory context를 추가하겠습니다 .

기본적으로 OS에서 얻은 메모리이며 분할 한 다음 한 번에 모두 해제 할 수 있습니다. 이것의 장점은 반복되는 소규모 호출 malloc()이 비용이 많이들 수 있다는 것입니다 (모든 메모리 할당에는 성능 비용이 있습니다. 프로그램의 논리 주소 공간에 메모리를 할당하는 데 걸리는 시간과 해당 주소 공간을 실제 메모리에 할당하는 데 걸리는 시간) 야구장을 아는 것처럼 큰 메모리 덩어리를 얻은 다음 변수에 필요한대로 / 어떻게 나눠 줄 수 있습니다.


'힙'의 동의어로 생각하십시오. 일반적으로 프로세스에는 힙 / 아레나가 하나만 있으며 모든 메모리 할당은 여기에서 발생합니다.

But, sometimes you have a situation where you would to group a series of allocations together (e.g. for performance, to avoid fragmentation, etc.). In that case, it's better to allocate a new heap/arena, and then for any allocation, you can decide which heap to allocate from.

For example, you might have a particle system where lots of objects of the same size are being frequently allocated and deallocated. To avoid fragmenting memory, you could allocate each particle from a heap which is only used for those particles, and all other allocations would come from the default heap.


From http://www.bozemanpass.com/info/linux/malloc/Linux_Heap_Contention.html:

The libc.so.x shared library contains the glibc component and the heap code resides inside it. The current implementation of the heap uses multiple independent sub-heaps called arenas. Each arena has its own mutex for concurrency protection. Thus if there are sufficient arenas within a process' heap, and a mechanism to distribute the threads' heap accesses evenly between them, then the potential for contention for the mutexes should be minimal. It turns out that this works well for allocations. In malloc(), a test is made to see if the mutex for current target arena for the current thread is free (trylock). If so then the arena is now locked and the allocation proceeds. If the mutex is busy then each remaining arena is tried in turn and used if the mutex is not busy. In the event that no arena can be locked without blocking, a fresh new arena is created. This arena by definition is not already locked, so the allocation can now proceed without blocking. Lastly, the ID of the arena last used by a thread is retained in thread local storage, and subsequently used as the first arena to try when malloc() is next called by that thread. Therefore all calls to malloc() will proceed without blocking.

You can also refer to this link:

http://www.codeproject.com/Articles/44850/Arena-Allocator-DTOR-and-Embedded-Preallocated-Buf

참고URL : https://stackoverflow.com/questions/12825148/what-is-the-meaning-of-the-term-arena-in-relation-to-memory

반응형