[UPDATED] Packet structure - Using pointers

12/09/2013 18:31 sala7mostafa#1
Hey ,
i made a new packet structure but this time using pointers as Fang said that pointers is better

[Only registered and activated users can see links. Click Here To Register...]

Regards ,
Salah Mostafa
12/09/2013 19:17 Super Aids#2
Instead of keeping to repeat this:
Code:
            fixed (byte* Packet = Buffer)
Then you could make a property for the pointer:
Code:
		public byte* Pointer
		{
			get
			{
				fixed (byte* p = Buffer)
					return p;
			}
		}
12/14/2013 22:40 12tails#3
or you guys could just check the COPSv6 source.... ^^
12/14/2013 23:17 CptSky#4
Quote:
Originally Posted by Super Aids View Post
Instead of keeping to repeat this:
Code:
            fixed (byte* Packet = Buffer)
Then you could make a property for the pointer:
Code:
		public byte* Pointer
		{
			get
			{
				fixed (byte* p = Buffer)
					return p;
			}
		}
The pointer is unsafe (:rolleyes:) The memory manager might move the managed memory after... The fixed keyword say to the memory manager to fix the memory during a period of time, after that, the pointer is no longer valid. So, everything you do on the pointer must be done inside the fixed's brackets.


Edit. For the thread itself, the code is not really faster as you're fixing the memory for each read and write... All operations should be done in one block to optimize the thing.
Or, just use unmanaged memory and/or just use a structure which will map all the buffer directly to values. (ref. COPS v6)
12/15/2013 06:53 Super Aids#5
Quote:
Originally Posted by CptSky View Post
The pointer is unsafe (:rolleyes:) The memory manager might move the managed memory after... The fixed keyword say to the memory manager to fix the memory during a period of time, after that, the pointer is no longer valid. So, everything you do on the pointer must be done inside the fixed's brackets.
Thanks, didn't actually know that