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.
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.
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.
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?
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.
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.
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,