public LargeBuffer(int size, int firstSegmentGlobalIndex) { FirstSegmentGlobalIndex = firstSegmentGlobalIndex; _bufferHandle = new SafeHeapHandle(size); _bufferPointer = (byte *)_bufferHandle.DangerousGetHandle(); }
private static string GetSchemeName(SafeHeapHandle <Guid> guid) { IntPtr schemeNameGuidPtr = guid.DangerousGetHandle(); int buffSize = 0; if (PowrProf.PowerReadFriendlyName(IntPtr.Zero, schemeNameGuidPtr, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, ref buffSize) != ReturnCodes.ERROR_SUCCESS) { return(string.Empty); } if (buffSize == 0) { return(string.Empty); } IntPtr schemeNamePtr = Marshal.AllocHGlobal(buffSize); if (PowrProf.PowerReadFriendlyName(IntPtr.Zero, schemeNameGuidPtr, IntPtr.Zero, IntPtr.Zero, schemeNamePtr, ref buffSize) != ReturnCodes.ERROR_SUCCESS) { Marshal.FreeHGlobal(schemeNamePtr); return(string.Empty); } string schemeName = Marshal.PtrToStringUni(schemeNamePtr); Marshal.FreeHGlobal(schemeNamePtr); return(schemeName); }
/// <summary> /// Create a buffer with at least the specified initial capacity in bytes. /// </summary> /// <exception cref="OverflowException">Thrown if trying to allocate more than a uint on 32bit.</exception> public HeapBuffer(ulong initialMinCapacity = 0) { _handle = HeapHandleCache.Instance.Acquire(initialMinCapacity); unsafe { _byteCapacity = (void *)(initialMinCapacity); } }
private unsafe void ReleaseHandle() { SafeHeapHandle handle; _handleLock.EnterWriteLock(); try { handle = _handle; _byteCapacity = null; _handle = null; } finally { _handleLock.ExitWriteLock(); } if (handle != null) { HeapHandleCache.Instance.Release(handle); } }
public static extern IntPtr HeapAlloc(SafeHeapHandle hHeap, HeapFlags flags, IntPtr size);