There are two methods for ACE memory allocation: ACE_Allocator base class and ACE_Malloc class.
1. Based on the ACE_Allocator allocation method, ACE provides multiple Allocator Distributors:
Distributor |
Description |
ACE_Allocator |
The interface class of the distributor class in ACE. These classes use inheritance and dynamic binding to provide flexibility. |
ACE_New_Allocator |
Memory Allocation and recovery are achieved through the new and delete in C ++. |
ACE_Static_Allocator |
Pre-allocate a large block of memory, which is extracted from the memory when malloc () is used. Once the default memory is allocated, it will no longer be released (not processed in the free () interface ). |
ACE_Cached_Allocator |
A piece of memory with n × fixed size is pre-allocated. The internal idle linked list is used to manage allocation and recovery. |
ACE_Dynamic_Allocator |
Similar to ACE_Cached_Allocator, a template parameter <class T> is added, and sizeof (T) is used as the pre-allocated fixed size. |
In actual applications, different dynamic memory allocation policies can be implemented through the dynamic binding technology of C ++, which is more flexible, but the problem is that the calling of virtual functions brings additional overhead.
If you call it directly (for example, directly using ACE_Dynamic_Allocator), it deviates from the original intention of Allocator design and lacks flexibility. However, I think direct calling is also a good way to improve the efficiency (especially for high performance requirements) when the application is fixed ).
2. Based on the memory pool allocation method, ACE provides multiple memory pools:
Pool name |
Description |
ACE_MMAP_Memory_Pool |
Mmap-based Shared Memory Pool. |
ACE_Sbrk_Memory_Pool |
Memory Pool Based on sbrk. (I have never used it. I don't know what it is) |
ACE_Shared_Memory_Pool |
Shared Memory Pool Based on system V shmipc. |
ACE_Pagefile_Memory_Pool |
The memory pool is based on the anonymous memory area allocated from files on windows pages. |
ACE_Local_Memory_Pool |
Local Memory Pool Based on C ++ new and delete. |
Template <ACE_MEM_POOL_1, class ACE_LOCK, class ACE_CB> classACE_Malloc_T;
The memory pool and lock act as template parameters of the distributor class and provide external polymorphism.
Template <classMALLOC> classACE_Allocator_Adapter: public ACE_Allocator;
Provides an adapter Method for different distributor classes.
The following call method is generally used:
Typedef ACE_Malloc <ACE_LOCAL_MEMORY_POOL, ACE_SYNCH_MUTEX> MUTEX_MALLOC;
TypedefACE_Allocator_Adapter <MUTEX_MALLOC> Mutex_Allocator;
In the ACE Chinese document, ACE_Malloc_T is configured using its template parameters during compilation, which is better than ACE_Allocator using virtual functions for polymorphism. But is the lock overhead completely ignored here?
3. Analysis and Summary
In my opinion, if communication between processes is not involved, allocator is enough to solve the problem. Although the calling of C ++ virtual functions causes some performance loss, however, this is completely acceptable.
If inter-process communication is involved, the memory pool is not necessarily an efficient implementation because of the existence of locks. At least in linux, inter-process communication can be achieved through a lockless dual-shared memory queue.
References:
ACE Chinese Document http://www.kuqin.com/ace-2002-12/Part-Two/Chapter-3.htm
ACE programmer tutorial