Beispiel #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;
        }
Beispiel #2
0
        /// <summary>
        /// Initializes a new instance of the memory block class.
        /// </summary>
        /// <param name="size">Size of the memory block</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.Reserve))
            {
                _pointer = MemoryManagement.Reserve(size);
            }
            else
            {
                _pointer = MemoryManagement.Allocate(size);
            }

            Size = size;
        }
Beispiel #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;
        }