Register for your free account! | Forgot your password?

You last visited: Today at 02:05

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



PacketBuilder

Discussion on PacketBuilder within the CO2 Private Server forum part of the Conquer Online 2 category.

Reply
 
Old 12/03/2011, 23:43   #16
 
elite*gold: 0
Join Date: May 2011
Posts: 1,769
Received Thanks: 756
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.
BaussHacker is offline  
Old 12/04/2011, 05:39   #17
 
Arco.'s Avatar
 
elite*gold: 0
Join Date: Feb 2011
Posts: 335
Received Thanks: 170
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;
        } 
Arco. is offline  
Old 12/04/2011, 14:23   #18


 
KraHen's Avatar
 
elite*gold: 0
Join Date: Jul 2006
Posts: 2,216
Received Thanks: 794
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.
KraHen is offline  
Reply


Similar Threads Similar Threads
Packetbuilder
10/21/2011 - CO2 Programming - 18 Replies
I have a simple packetbuilder right now, but is there any way that this can be optimized for efficiency? class PacketBuilder { private byte buffer; public PacketBuilder(byte Buffer) { buffer = Buffer; } public void ZeroFill(byte Buffer, ushort Offset, ushort Count) {
Packetbuilder
10/13/2011 - General Coding - 0 Replies
I have a simple packetbuilder right now, but is there any way that this can be optimized for efficiency? class PacketBuilder { private byte buffer; public PacketBuilder(byte Buffer) { buffer = Buffer; } public void ZeroFill(byte Buffer, ushort Offset, ushort Count) {



All times are GMT +1. The time now is 02:05.


Powered by vBulletin®
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2025 elitepvpers All Rights Reserved.