1
\$\begingroup\$

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
{
    [FieldOffset(0)]
    public int size;
    [FieldOffset(4)]
    public int opcode;
    [FieldOffset(32)]
    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.

\$\endgroup\$
3
  • \$\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 Sep 4 '14 at 5:33
  • \$\begingroup\$ No, I didn't profile anything yet, just considering options \$\endgroup\$ – Leandro Battochio Sep 4 '14 at 6:13
  • 2
    \$\begingroup\$ Then do whatever works and optimize it IF it becomes a bottle-neck. \$\endgroup\$ – Kromster Sep 4 '14 at 6:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.