Beispiel #1
0
 /// <summary>
 /// Marks this memory block as not used anymore.
 /// </summary>
 /// <param name="freeManagedRes">Doesn't really matter.</param>
 public void Dispose(bool freeManagedRes)
 {
     if (this.Disposed)
     {
         return;
     }
     this.Disposed = true;
     if (this.Managed)
     {
         CryMarshal.Free(this.Handle, true);
     }
     GC.SuppressFinalize(this);
 }
Beispiel #2
0
 /// <summary>
 /// Creates new instance of type <see cref="NativeMemoryBlock"/> while allocating memory for it.
 /// </summary>
 /// <param name="size">Size of the memory block in bytes to allocate.</param>
 public NativeMemoryBlock(ulong size)
 {
     if (size == 0)
     {
         this.Disposed = true;
         this.Size     = 0;
         this.Handle   = IntPtr.Zero;
         this.Managed  = false;
     }
     else
     {
         this.Size   = size;
         this.Handle = CryMarshal.Allocate(size);
         if (this.Handle == IntPtr.Zero)
         {
             throw new OutOfMemoryException("Unable to allocate native memory block.");
         }
         this.Managed  = true;
         this.Disposed = false;
     }
 }