Ejemplo n.º 1
0
        /// <summary>
        /// Clone this memory object. this method will be allocate new memory area.
        /// </summary>
        /// <returns>New allocated memory object.</returns>
        public object Clone()
        {
            Memory memory = Allocation(Size);

            MemAPIs.CopyMemory(Address, memory.Address, Size);

            return(memory);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Allocates a block of memory from a heap. The allocated memory is not movable.
        /// </summary>
        /// <param name="size">The number of bytes to be allocated.</param>
        /// <param name="heapHandle">A handle to the heap from which the memory will be allocated.</param>
        /// <returns>If the function succeeds, Memory.Address member not null.</returns>
        public static Memory Allocation(uint size, Heap heapHandle)
        {
            IntPtr allocMemory = MemAPIs.HeapAlloc(heapHandle, HeapFlags.HEAP_NONE, size);

            if (allocMemory != null)
            {
                Memory memory = new Memory();
                memory.Address         = allocMemory;
                memory.Size            = size;
                memory.HeapHandle      = heapHandle;
                memory.IsFreeOnDispose = false;

                return(memory);
            }
            else
            {
                throw new OutOfMemoryException("Allocation Failure.");
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Allocates memory for the Heap Handle returned by the GetProcessHeap() method. The allocated memory is not movable.
 /// </summary>
 /// <param name="size">The number of bytes to be allocated.</param>
 /// <returns>If the function succeeds, Memory.Address member not null.</returns>
 public static Memory Allocation(uint size) => Allocation(size, MemAPIs.GetProcessHeap());
Ejemplo n.º 4
0
 /// <summary>
 /// Release pointed heap memory.
 /// </summary>
 public void Free()
 {
     MemAPIs.HeapFree(HeapHandle, HeapFlags.HEAP_NONE, Address);
     this.Address = IntPtr.Zero;
 }