|
下面是我封装的一个消息队列类,不知道这样会不会内存泄露,大家帮忙看看- class MessageQueue
- {
- public:
- MessageQueue(const int nMessageLength)
- {
- m_pMessageBlock = new ACE_Message_Block(nMessageLength);
- m_nMessageLength = nMessageLength;
- m_clMessageQueue.high_water_mark (nMessageLength*1000);
- m_clMessageQueue.low_water_mark (nMessageLength*1000);
- }
- ~MessageQueue(){delete m_pMessageBlock;}
- bool Send(char* buffer);
- bool Receive(char* buffer);
- private:
- int m_nMessageLength;
- ACE_Message_Queue<ACE_MT_SYNCH> m_clMessageQueue;
- ACE_Message_Block* m_pMessageBlock;
- };
- //
- //发送
- //
- bool MessageQueue::Send(char* buffer)
- {
- if(NULL == buffer)return false;
- ACE_Time_Value initial (0);
- memcpy(m_pMessageBlock->wr_ptr(),buffer,m_nMessageLength);
- if(m_clMessageQueue.enqueue(m_pMessageBlock,&initial) == -1)return false;
- return true;
- }
- //
- //接收
- //
- bool MessageQueue::Receive(char* buffer)
- {
- if(NULL == buffer)return false;
- ACE_Time_Value initial (0);
- if(m_clMessageQueue.dequeue(m_pMessageBlock,&initial) == -1)return false;
- memcpy(buffer,m_pMessageBlock->rd_ptr(),m_nMessageLength);
- return true;
- }
复制代码 |
|