What is the best performant solution to handle received data from socket, in a MMORPG game? Is it good to have something like:

[StructLayout(LayoutKind.Explicit, Pack = 1)]
public struct LoginPacket
    public int size;
    public int opcode;
    public int someOtherImportantOffsetInPacket;

And then when every packet is received I create the correct struct for the received packet, to access its information easier? Or the best performant solution is if I just pass the byte[] to the function and use functions like BitConverter.ToInt32 ? I know BitConverter is slow, but I already have my own class that does the same thing in a faster way.

  • \$\begingroup\$ Did you profile your code in actual usage scenario, or are you optimizing non-existent bottle-neck? You should be able to swap processing method in a few minutes and compare. \$\endgroup\$
    – Kromster
    Commented Sep 4, 2014 at 5:33
  • \$\begingroup\$ No, I didn't profile anything yet, just considering options \$\endgroup\$ Commented Sep 4, 2014 at 6:13
  • 2
    \$\begingroup\$ Then do whatever works and optimize it IF it becomes a bottle-neck. \$\endgroup\$
    – Kromster
    Commented Sep 4, 2014 at 6:36


You must log in to answer this question.

Browse other questions tagged .