Memory Management Mechanism learning in ACE

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.