Exemple #1
0
        /// <summary>
        /// Creates a new instance of the memory block class.
        /// </summary>
        /// <param name="size">Size of the memory block in bytes</param>
        /// <param name="flags">Flags that controls memory block memory allocation</param>
        /// <exception cref="OutOfMemoryException">Throw when there's no enough memory to allocate the requested size</exception>
        /// <exception cref="PlatformNotSupportedException">Throw when the current platform is not supported</exception>
        public MemoryBlock(ulong size, MemoryAllocationFlags flags = MemoryAllocationFlags.None)
        {
            if (flags.HasFlag(MemoryAllocationFlags.Mirrorable))
            {
                _sharedMemory     = MemoryManagement.CreateSharedMemory(size, flags.HasFlag(MemoryAllocationFlags.Reserve));
                _pointer          = MemoryManagement.MapSharedMemory(_sharedMemory, size);
                _usesSharedMemory = true;
            }
            else if (flags.HasFlag(MemoryAllocationFlags.Reserve))
            {
                _viewCompatible      = flags.HasFlag(MemoryAllocationFlags.ViewCompatible);
                _forceWindows4KBView = flags.HasFlag(MemoryAllocationFlags.ForceWindows4KBViewMapping);
                _pointer             = MemoryManagement.Reserve(size, _viewCompatible);
            }
            else
            {
                _pointer = MemoryManagement.Allocate(size);
            }

            Size = size;

            _viewStorages = new ConcurrentDictionary <MemoryBlock, byte>();
            _viewStorages.TryAdd(this, 0);
            _viewCount = 1;
        }
Exemple #2
0
 /// <summary>
 /// Creates a new instance of the memory block class, with a existing backing storage.
 /// </summary>
 /// <param name="size">Size of the memory block in bytes</param>
 /// <param name="sharedMemory">Shared memory to use as backing storage for this block</param>
 /// <exception cref="OutOfMemoryException">Throw when there's no enough address space left to map the shared memory</exception>
 /// <exception cref="PlatformNotSupportedException">Throw when the current platform is not supported</exception>
 private MemoryBlock(ulong size, IntPtr sharedMemory)
 {
     _pointer          = MemoryManagement.MapSharedMemory(sharedMemory, size);
     Size              = size;
     _usesSharedMemory = true;
     _isMirror         = true;
 }
Exemple #3
0
        /// <summary>
        /// Creates a new instance of the memory block class.
        /// </summary>
        /// <param name="size">Size of the memory block in bytes</param>
        /// <param name="flags">Flags that controls memory block memory allocation</param>
        /// <exception cref="OutOfMemoryException">Throw when there's no enough memory to allocate the requested size</exception>
        /// <exception cref="PlatformNotSupportedException">Throw when the current platform is not supported</exception>
        public MemoryBlock(ulong size, MemoryAllocationFlags flags = MemoryAllocationFlags.None)
        {
            if (flags.HasFlag(MemoryAllocationFlags.Mirrorable))
            {
                _sharedMemory     = MemoryManagement.CreateSharedMemory(size, flags.HasFlag(MemoryAllocationFlags.Reserve));
                _pointer          = MemoryManagement.MapSharedMemory(_sharedMemory);
                _usesSharedMemory = true;
            }
            else if (flags.HasFlag(MemoryAllocationFlags.Reserve))
            {
                _pointer = MemoryManagement.Reserve(size);
            }
            else
            {
                _pointer = MemoryManagement.Allocate(size);
            }

            Size = size;
        }