how does microsoft do this?

Started by
12 comments, last by fireking 21 years, 6 months ago
quote:Original post by Xiol
However, the extra instructions required to access unpadded data, especially in a tight inner loop, could cause a noticible performace loss. (Probably not, but it could).


You could have two structures with the same data but one is padded and the other isn''t. When you receive the unpadded struct, you copy all members into the padded one and use it for all your operations.
Advertisement
quote:Original post by Prosper/LOADED
You could have two structures with the same data but one is padded and the other isn''t. When you receive the unpadded struct, you copy all members into the padded one and use it for all your operations.


Of course, how is that any different to the pack/unpack method?

If I had my way, I''d have all of you shot!

codeka.com - Just click it.
Sending structs over a streaming protocol like TCP is a bad idea. There''s no guarantee that you''ll get the whole struct with one call to recv().
You can either memcpy your struct to an array of chars and send that or cast your struct as an array of chars. It''s the same thing.

You should, however, never RECV to a struct or if you really want to, RECV to a temporary struct (it makes checking the header a little easier) and copy it to an array of chars. Otherwise you''re shooting yourself in the foot when you go to see if you have the whole message or two or more messages in one packet. You need to recieve to an array of chars and then do some checking before you memcpy the char buffer into the struct.

With my Winsock class I have a message class that handles all of this so when I call GetMessage() it will only return a message struct if there''s a complete message available. Then I just keep calling GetMessage() until it doesn''t return a message.

The method sets the message.type to -1 of there''s not a message available. There are a couple other negative numbers it''ll return for checking why it didn''t return a message. Those were just for debugging though.

Ben


IcarusIndie.com [ The Rabbit Hole | The Labyrinth | DevZone | Gang Wars | The Wall | Hosting | Tiberian Merchandise!!!! | GameShot ]

This topic is closed to new replies.

Advertisement