🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Message Handles

Started by
0 comments, last by WMiller 23 years, 1 month ago
I do not see a perfect way to assign handles to classes across a distributed program. Let''s say that I want to pack up a class into bytes, and ship it to a homogeneous machine. I''d have the first couple bytes be some ID for the class, the next couple bytes represent how big the data is, and have the rest of the bytes be the actual data contained by the class, or something like that. On the far end, I''ve got some kind of map or dictionary that looks at the first number, and calls some function with the rest of the data and the size of the data as a parameter. The issue is: How do you pick the number that represents the handle to the class? Here are some ways I''ve thought of and why I don''t like them: 1) Hard code the handle: Description: In each source file, assign an immediate value (like 7) to be the handle for this class. Why I don''t Like It: Since numbers aren''t centrally assigned, there''s no compile-time check to see if two classes are accidentally using the same Id number. 2) Use a central header Description: Each source file uses a named constant. The actual value of the constant is in a central header file, and every source file that needs a value links to this same file. In this way, there''s only one list of numbers so it''s pretty straightforward to resolve problems with assignments. Why I don''t like it: Everything is coupled to the central header. The central header is not reusable from application to application. 3) Assign handles at run-time Description: Classes call a handle factory to get assigned a number. Handles are given out in a predicatable manner, and these are stored in private static variables of *every* class. (Note that if you inherit a class, you really need to have your own static int handle -- using the parent''s would be incorrect). Either the application or "static object constructor magic" is used to register all classes. Why I don''t like it: It''s complicated. Programs must all assign handles in the same order or it gets really complicated. Wondered if you had any ideas? I''d be happy with a good solution for homogeneous systems, but something that''s universal would be even better.
Advertisement
Sun faced the same problem when they wrote java, you might want to look into their scheme, i think it used the 3rd method, not sure i didnt look into java that closely. There are other protocols which may be doing something simular such as DCOM and CORBA, might want to look into them too.

Here is a link on a DCOM and CORBA comparaision i''ve found useful :

http://www.jonathanclark.com/diary/dcom_corba/

Good Luck

-ddn

This topic is closed to new replies.

Advertisement