[Ace-users] [ace-users] Putting an object into an ACE_Message_Block

Steve Huston shuston at riverace.com
Wed Jan 2 17:43:06 CST 2008

Hi David,

> I may be trying to do this incorrectly, but I want to put and
> object into a message block of an ACE_Message_Block.


> Since the wr_ptr method assumes a string,

No, not really. It's defined in terms of "char*", but that's just
because it's a set of bytes.

> how would I set the message data to an object?

You can:

1. Create a message block that uses your existing object as the data
2. Store a pointer to the object in the message block.
3. Construct your object in the block.

> Here is an example of the code I am trying to get to work:
> bool StaticQueue::AddMessage(EventMessage &P_message)
> {
>     bool retVal = true;
>     ACE_Message_Block *mb = new
>     mb->wr_ptr(P_message);

No... You can do this to create the message block referring to your
existing EventMessage:

 ACE_Message_Block *mb = new ACE_Message_Block (&P_message, sizeof
 mb->wr_ptr (sizeof (EventMessage));

That would leave you to still needing to clean up P_message later;
releasing the message block will not free the EventMessage.

> How do I get the object into the payload of the message block?

The above does that, and the block does not control the lifetime of
the object's memory. You could also construct the message block as
your original code did and then either copy the object in or construct
one in place.


Steve Huston, Riverace Corporation
Want to take ACE training on YOUR schedule?
See http://www.riverace.com/training.htm

More information about the Ace-users mailing list