Jump to content
  • Advertisement
Sign in to follow this  
Croc

Message Passing

This topic is 4884 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am currently considering experimenting with a task based engine architecture where each subsystem is a task and there is no synchronous communication between these tasks, only asynchronous. I have a problem with the CMessage class which would represent this asynchronous communication for the following reasons: I would like to be able to pass some variables (whose type would vary between different message types). To achieve this, I have considered using void pointers (void*) in my CMessage class but this would require one of two approaches.
  • I could dynamically allocate memory for the variables when sending the message which the CMessage class would later have responsibility in cleaning up, but this is obviously undesireable due to dynamic allocation of memory within the gameloop.
  • The void pointer could point to a member variable held by the sender class, but this has the undesireable effect of increasing coupling between tasks, thus circumventing the entire point of the exercise.
I have also considered using a templated CMessage class which would ensure type safety and allow passing the variables without dynamically allocating memory. However, this has a different disadvantage in that a templated CMessage class would not be able to be placed in a CMessage pool and so the CMessage class itself would have to dynamically created when sending each message. Thus, I was wondering whether anyone would have any thoughts as to approaching this? - Oscar [smile]

Share this post


Link to post
Share on other sites
Advertisement
at the last company i worked for we used an home grown thread-safe queue template for things like this. there would be a seperate instance of this queue for each type of 'message' being passed.

to mix messages that are really different types you may want a tuplespace, there are no really good c++ tuplespace libs out there (except the costly TSpaces by IBM and the outdated Linda). ruby has a nice one but that's not going to help.

i do remember there being one mentioned in a chat room that looked nice but i can't seem to find it. google is not helping. the only google clues i have are that i think it was called tcom (or tcomm), it had a class named TupleSpace.

the problem you are trying to solve is not trival (well, a *good* solution is not not trival) but would be very useful.

you might also want to look into "Flow Based Programming" as it sounds like that's what you are trying to do.

Share this post


Link to post
Share on other sites
Quote:
Original post by Croc

I have also considered using a templated CMessage class which would ensure type safety and allow passing the variables without dynamically allocating memory.
However, this has a different disadvantage in that a templated CMessage class would not be able to be placed in a CMessage pool and so the CMessage class itself would have to dynamically created when sending each message.


Perhaps I misunderstand; but what would be wrong with declaring an abstract base class "CMessage", and deriving a templated T_CMessage<>" class from it, or something?


Share this post


Link to post
Share on other sites
the problem is (i think) that he wants objects of different types queued up in the same queue. a templated queue would still only allow objects of one type (per queue).

Share this post


Link to post
Share on other sites
Quote:
Original post by Verg
Perhaps I misunderstand; but what would be wrong with declaring an abstract base class "CMessage", and deriving a templated T_CMessage<>" class from it, or something?


I apologise as I may have not been verbose enough. I meant an Object Pool which would create a bunch of CMessage objects and manage handing them out when a message is to be sent and placing them back into the pool/list when the message is no longer needed. This would eliminate the need to dynamically allocate a CMessage object when a message is to be sent (desireable within the gameloop).
This is as far as I can see, not possible using a templated CMessage class (even if it derived from a base) without using a pool/list for each message type unfortunately.

- Oscar [smile]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!