Register for your free account! | Forgot your password?

You last visited: Today at 01:12

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

Advertisement



Pointers vs. Safecode

Discussion on Pointers vs. Safecode within the CO2 Private Server forum part of the Conquer Online 2 category.

Reply
 
Old   #1
 
Arco.'s Avatar
 
elite*gold: 0
Join Date: Feb 2011
Posts: 335
Received Thanks: 170
Pointers vs. Safecode

Really, what is the difference between doing:
Code:
                *(ushort*)PTR = (ushort)Buffer.Length;
                *((ushort*)(PTR + 2)) = 2030;
                *((uint*)(PTR + 4)) = npc.StaticID;
                *((ushort*)(PTR + 8)) = (ushort)npc.Cords.Position.X;
                *((ushort*)(PTR + 10)) = (ushort)npc.Cords.Position.Y;
                *((ushort*)(PTR + 12)) = (ushort)(npc.StaticID + (byte)npc.Direction);
                *((ushort*)(PTR + 14)) = npc.Interaction;
And

Code:
            PacketBuilder Packet = new PacketBuilder(new byte[20]);
            Packet.WriteUInt16(Packet.Packet.Length);
            Packet.WriteUInt16(2030);
            Packet.WriteUInt32((uint)Type);
            Packet.WriteUInt16(X);
            Packet.WriteUInt16(Y);
            Packet.WriteUInt16(SubType);
            Packet.WriteUInt16(Dir);
            Packet.WriteUInt32((uint)Flag);
Whats the pros and cons of each one?
Arco. is offline  
Old 03/10/2011, 21:03   #2
 
elite*gold: 0
Join Date: Nov 2010
Posts: 1,162
Received Thanks: 370
The first one is writing the buffer direct and you can send it direct.
The second is writing to a packetbuilder, which you're sending to the client after.
You can use the 2nd one without writing it in an fixed block, because the fixed block is in the builder, where the first one have to be in a fixed block.

Don't know if I explained it right, but that's how I see it.
Syst3m_W1z4rd is offline  
Old 03/10/2011, 21:14   #3
 
Arco.'s Avatar
 
elite*gold: 0
Join Date: Feb 2011
Posts: 335
Received Thanks: 170
I know what they do, I want to know the pros v. cons of each.
Arco. is offline  
Old 03/10/2011, 21:16   #4
 
elite*gold: 21
Join Date: Jul 2005
Posts: 9,193
Received Thanks: 5,380
Pointers are faster/more efficient.

Even more efficient is writing it using a structure (that way it's just stored in memory) and you can just build a packet based on the memory addresses.

Combine that with a static send buffer and you have yourself no need to ever assign new byte arrays for these new packets and completely skip all that overhead/memory usage.
pro4never is offline  
Thanks
2 Users
Old 03/11/2011, 01:06   #5
 
elite*gold: 0
Join Date: Jun 2009
Posts: 787
Received Thanks: 314
doing something like *(ptr + x) = value directly translates to one assembly instruction (or at least less than using mathematical operators to imitate it).

also doing something like
struct packet {
short type;
short size;
}
p.type = 5;
p.size = 4;
is literally the same thing as *(ptr + offset) = ... at the most basic level. However it should be noted that in C# structs are stored on the stack (well struct s = new stuct()...), and allocating a byte[] is done on the heap.

Fixing a byte[] down into a byte* however isn't the fastest or best operation.
_tao4229_ is offline  
Thanks
1 User
Old 03/11/2011, 03:36   #6
 
Arco.'s Avatar
 
elite*gold: 0
Join Date: Feb 2011
Posts: 335
Received Thanks: 170
Quote:
Originally Posted by _tao4229_ View Post
doing something like *(ptr + x) = value directly translates to one assembly instruction (or at least less than using mathematical operators to imitate it).

also doing something like
struct packet {
short type;
short size;
}
p.type = 5;
p.size = 4;
is literally the same thing as *(ptr + offset) = ... at the most basic level. However it should be noted that in C# structs are stored on the stack (well struct s = new stuct()...), and allocating a byte[] is done on the heap.

Fixing a byte[] down into a byte* however isn't the fastest or best operation.
Then what do you think would be the best operation?
Arco. is offline  
Old 03/11/2011, 03:49   #7
 
elite*gold: 0
Join Date: Jun 2009
Posts: 787
Received Thanks: 314
As with everything, it's situational.
_tao4229_ is offline  
Old 03/12/2011, 15:45   #8
 
elite*gold: 0
Join Date: Sep 2008
Posts: 1,683
Received Thanks: 506
If you handle them propertly, pointers are much faster. On the other hand, if you don't handle them correctly, they can cause all kinds of problems.

I would avoid them, the CLR is pretty **** fast, you may find that you'll never have to resort to unsafe code.

Whether to use pointers or not is the least important thing to worry a bout.

I also think it depends on how much you're going to use pointers, only for packet structures? You really want to go into that much complexity for only packet structures?

Oh and let me add when I would use pointers.
- In image processing.
- When using pinvoke calls.
- If data processing is the bottleneck of your application.

Conclusion:
Don't use pointers in .NET, at this point, there is no need for it in a private server. You'll server is going to be a I/O bound application, not CPU bound.
Basser is offline  
Old 03/14/2011, 02:24   #9
 
lostsolder05's Avatar
 
elite*gold: 20
Join Date: Jan 2006
Posts: 890
Received Thanks: 241
Quote:
Originally Posted by Basser View Post
If you handle them propertly, pointers are much faster. On the other hand, if you don't handle them correctly, they can cause all kinds of problems.

I would avoid them, the CLR is pretty **** fast, you may find that you'll never have to resort to unsafe code.

Whether to use pointers or not is the least important thing to worry a bout.

I also think it depends on how much you're going to use pointers, only for packet structures? You really want to go into that much complexity for only packet structures?

Oh and let me add when I would use pointers.
- In image processing.
- When using pinvoke calls.
- If data processing is the bottleneck of your application.

Conclusion:
Don't use pointers in .NET, at this point, there is no need for it in a private server. You'll server is going to be a I/O bound application, not CPU bound.
It depends on what your using the pointers for. If it's a single pointer it's not going to make a significant difference. It'd advice staying away from pointers though considering you made this thread.
lostsolder05 is online now  
Reply


Similar Threads Similar Threads
About Pointers
01/01/2010 - Cabal Online - 1 Replies
Can someone explain briefly how to make ur do pointers? thanks and happy new year!
pointers
06/22/2009 - Grand Chase Philippines - 4 Replies
im just wondering how to use pointers ? anyone can help me?
Help about pointers
05/17/2009 - Grand Chase Philippines - 5 Replies
can anyone teach me how to do this para d na poh aq mauli ulit mag scan ng address evertime I open PChack
Pointers with CE, help
01/15/2009 - General Coding - 0 Replies
Hello! Guys im having problems when I try to search for a pointer of a dynamic address using CE 5.4. Always when I press "Find out what writes to this address" or similar options the game just will crash. I'm not able to go further with this problem. If anyone knows how to fix this problem, or knows another way to do it give me a tip and i'll try to find it and learn it. Thanks,
Pointers with CE
01/15/2009 - Dekaron - 0 Replies
Hello! Guys im having problems when I try to search for a pointer of a dynamic address using CE 5.4. Always when I press "Find out what writes to this address" or similar options the game just will crash. I'm not able to go further with this problem. If anyone knows how to fix this problem, or knows another way to do it give me a tip and i'll try to find it and learn it. Thanks,



All times are GMT +1. The time now is 01:12.


Powered by vBulletin®
Copyright ©2000 - 2026, 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 ©2026 elitepvpers All Rights Reserved.