/// <summary>
/// Wrapper for access to the native heap. Dispose to free the memory. Try to use with using statements.
/// Does not allocate zero size buffers, and will free the existing native buffer if capacity is dropped to zero.
- ///
-#if !FEATURE_CORECLR
- /// NativeBuffer utilizes a cache of heap buffers.
-#endif
/// </summary>
/// <remarks>
/// Suggested use through P/Invoke: define DllImport arguments that take a byte buffer as SafeHandle.
/// </remarks>
internal class NativeBuffer : IDisposable
{
-#if !FEATURE_CORECLR
- // The need for caching the heap handles isn't as great in CoreCLR as most current usages of this class'
- // consumers are wrapped by CoreFx. (As opposed to NetFX 4.6 where there is no wrapping)
- private readonly static SafeHeapHandleCache s_handleCache;
-#endif
[System.Security.SecurityCritical]
private readonly static SafeHandle s_emptyHandle;
[System.Security.SecurityCritical]
static NativeBuffer()
{
s_emptyHandle = new EmptySafeHandle();
-#if !FEATURE_CORECLR
- s_handleCache = new SafeHeapHandleCache();
-#endif
}
/// <summary>
if (_handle == null)
{
-#if FEATURE_CORECLR
_handle = new SafeHeapHandle(byteLength);
-#else
- _handle = s_handleCache.Acquire(byteLength);
-#endif
}
else
{
{
if (_handle != null)
{
-#if !FEATURE_CORECLR
- s_handleCache.Release(_handle);
-#endif
_capacity = 0;
_handle = null;
}