消息块ACE_Message_Block结构的分析
- 包含一个指向带引用计数功能的ACE_Data_Block对象,该对象指向正在的数据缓冲区,这样可以在ACE_Message_Block对象之间灵活、高效地共享数据
- 一个或多个ACE_Message_Blocks对象可以连接起来组成一条链
- ACE_Message_Blocks对象可以连接起来组成一个双向的链表,进而形成消息队列
class ACE_Export ACE_Message_Block
{
public:
friend class ACE_Data_Block;
/*******************************************************
* 函数声明
*******************************************************/
/// Pointer to beginning of next read.
/// 数据读指针,实际上是一个相对起始地址的偏移量
size_t rd_ptr_; /// Pointer to beginning of next write.
/// 数据写指针,实际上是一个相对起始地址的偏移量
size_t wr_ptr_; /// Priority of message.
/// 表示消息的优先级,用于优先级消息队列
unsigned long priority_; #if defined (ACE_HAS_TIMED_MESSAGE_BLOCKS)
/// Execution time associated with the message.
/// 消息块的时间属性,用于实时消息队列
ACE_Time_Value execution_time_; /// Absolute deadline time for message.
ACE_Time_Value deadline_time_;
#endif /* ACE_HAS_TIMED_MESSAGE_BLOCKS */ // = Links to other ACE_Message_Block *s.
/// Pointer to next message block in the chain.
/// 消息链指针,多个消息块可以连在一起,构成一个消息块链
ACE_Message_Block *cont_; /// Pointer to next message in the list.
/// 表示后一个消息指针
ACE_Message_Block *next_; /// Pointer to previous message in the list.
/// 前一个消息指针
ACE_Message_Block *prev_; /// Misc flags (e.g., DONT_DELETE and USER_FLAGS).
/// 是ACE_Data_Block删除标志,表示该实例下的data_block_是否要删除
ACE_Message_Block::Message_Flags flags_; /// Pointer to the reference counted data structure that contains the
/// actual memory buffer.
/// 数据块指针
ACE_Data_Block *data_block_; /// The allocator used to destroy ourselves when release is called
/// and create new message blocks on duplicate.
/// 消息块内存分配器
ACE_Allocator *message_block_allocator_; private:
// = Disallow these operations for now (use <clone> instead).
ACE_Message_Block &operator= (const ACE_Message_Block &);
ACE_Message_Block (const ACE_Message_Block &);
};
- 每次写入数据时,写指针会偏移实际写入数据的长度,每次读出数据时,读指针会偏移实际读出数据的长度。它们的差就是当前消息块中含有的数据量。
- ACE_Message_Block和ACE_Data_Block结构关系如图所示