How to Use the ace_message_block distributor

Source: Internet
Author: User
Ace_messae_block combines ace_allocator to make ace_message_block more flexible. This article describes how to use ace_message_block and ace_allocator and the precautions.
First, let's look at the Construction Function of ace_message_block: Ace_message_block (size_t size,
Ace_message_type type = Mb_data,
Ace_message_block * Cont =   0 ,
Const   Char   * Data =   0 ,
Ace_allocator * Allocator_strategy =   0 ,
Ace_lock * Locking_strategy =   0 ,
Unsigned Long Priority = Ace_default_message_block_priority,
Const Ace_time_value & Execution_time = Ace_time_value: zero,
Const Ace_time_value & Deadline_time = Ace_time_value: max_time,
Ace_allocator * Data_block_allocator =   0 ,
Ace_allocator * Message_block_allocator =   0 );

Three aliclouders are used: allocator_stratey, data_block_allocator, and message_block_allocator. The three aliclouders allocate memory for two objects in ace_message_block and the devices themselves. data_block, and the char * Memory pointed to by data_block.
In this way, we can implement the Effect of Pre-allocating memory by inputting three sub-shards.

Msg_allocator _ = New Ace_cached_allocator < Ace_message_block, ace_synch_mutex > (Msgcount );
Data_allocator _ = New Ace_cached_allocator < Ace_data_block, ace_synch_mutex > (Buffcount );
Buff_allocator _ = New Ace_cached_allocator < Mem_buf, ace_synch_mutex > (Buffcount );

ViewCodeYou can find that when calling its release method, it will first check whether it is allocated. If it is not used, delete it directly. If a distributor is used, the memory will be returned to the distributor.
You must also pay attention to a parameter, locking_strategy, which is a multi-threaded synchronization lock. It is mainly used for thread security control during the shallow copy or release process. For example, you need to increase or decrease the reference counter when calling duplicate or release.
How to reasonably use locking_strategy in the next writing so that it does not affect efficiency ,:)

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.