PacketBuilder

12/03/2011 23:43 BaussHacker#16
Quote:
Originally Posted by mateo136 View Post
I know this is stupid question but what exactly is a packetBuilder?
A wrapper used to build your data packets, whom you're going to send later on.
12/04/2011 05:39 Arco.#17
Quote:
Originally Posted by KraHen View Post
PHP Code:
public static byte[] Serialize(object Data)
        {
            
int size Marshal.SizeOf(Data);
            
byte[] bdata = new byte[size];
            
GCHandle handle GCHandle.Alloc(bdataGCHandleType.Pinned);
            
Marshal.StructureToPtr(Datahandle.AddrOfPinnedObject(), false);
            
handle.Free();
            return 
bdata;
        } 
What would be the difference between that and
PHP Code:
public Byte[] ToByteArray()
        {
            
Byte[] Buffer = new Byte[Packet.pLength];
            
Marshal.Copy((IntPtr)Packet.pBufferBuffer0Packet.pLength);
            return 
Buffer;
        } 
12/04/2011 14:23 KraHen#18
Assuming in your code "Packet" is a struct, that (IntPtr) would convert your struct to an IntPtr. Seems simple enough. That sounds like a lot of movement, as far as I understand it.

My code creates a buffer, pins it in the memory so there would be no movement induced by the GC, and move the bytes in my struct directly to my pinned buffer, without any intermediate "helper".

EDIT : I just saw that you`re actually passing Packet.pBuffer, which shouldn`t be a struct lol. In that case marshalling is totally pointless.