Author: James CE Johnson

ACE Tutorial 012
Passing classes through ACE_Message_Queue

Last time around we put an object into a message queue by using the copy() method to create a duplicate of the object. That's probably OK for simple objects that aren't very large. However, if you have an object that contains pointers or tons of data then that approach is going to cause problems.

What we'll do in this tutorial is specialize the ACE_Message_Block object so that it can carry our data more efficiently. As you'll see, this isn't very difficult at all.

Kirthika's abstract:

Here, a Message_Block class is derived from ACE_Message_Block and is used to hold a pointer to the object of class Work. Also, the block has a header containing text. This example simply illustrates a cleaner way of utilizing Message_Blocks to store objects rather than copying their contents.

The ACE_Barrier class has been used in the Task class which blocks the threads until all of them are rearing to go and grab a block from the queue and process it.

Thus a message queue can be used to accomplish a variety of tasks by storing a object pointer in the blocks.

[Tutorial Index] [Continue This Tutorial]