/// <summary> /// Let GC collect the memory area /// </summary> private static void Deallocate() { if (allocated) { ntdRingBufferHandle.Free(); ntdFullRingBufferHandle.Free(); finalCursorHandle.Free(); ntdRingBuffer = null; ntdFullRingBuffer = null; nativeTouchDataQueue = null; allocated = false; } }
/// <summary> /// C# is holding several important memory area for native side to write to. /// </summary> private static void AllocateIfNotYet(StartOption startOption) { if (!allocated) { ntdRingBuffer = new NativeTouchData[startOption.ringBufferSize]; ntdFullRingBuffer = new NativeTouchDataFull[startOption.ringBufferSize]; dekker = new int[3]; finalCursorStorage = new int[1]; ntdRingBufferHandle = GCHandle.Alloc(ntdRingBuffer, GCHandleType.Pinned); ntdFullRingBufferHandle = GCHandle.Alloc(ntdFullRingBuffer, GCHandleType.Pinned); finalCursorHandle = GCHandle.Alloc(finalCursorStorage, GCHandleType.Pinned); dekkerHandle = GCHandle.Alloc(dekker, GCHandleType.Pinned); nativeTouchDataQueue = new NativeTouchRingBuffer(); activeRingBufferSize = startOption.ringBufferSize; allocated = true; } }