Exemplo n.º 1
0
        object RangeAllocator <LocalAllocation> .IMoveListener.Save(RangeAllocator <LocalAllocation> .Range range)
        {
            var bytes = _globalHeap.GetBuffer(_globalHandle, false);

            var save = new byte[range.Size];

            Buffer.BlockCopy(bytes, range.Position, save, 0, range.Size);
            return(save);
        }
Exemplo n.º 2
0
        void RangeAllocator <LocalAllocation> .IMoveListener.Load(RangeAllocator <LocalAllocation> .Range range, object data)
        {
            var bytes = _globalHeap.GetBuffer(_globalHandle, true);

            Buffer.BlockCopy((byte[])data, 0, bytes, range.Position, range.Size);

            if (range.User.Moveable)
            {
                bytes.WriteWord(range.User.handleOrPtr, (ushort)range.Position);
            }
        }
Exemplo n.º 3
0
        void RangeAllocator <LocalAllocation> .IMoveListener.Move(RangeAllocator <LocalAllocation> .Range range, int newPosition)
        {
            var bytes = _globalHeap.GetBuffer(_globalHandle, true);

            Buffer.BlockCopy(bytes, range.Position, bytes, newPosition, range.Size);

            // Update the local handle to point to the new location
            if (range.User.Moveable)
            {
                bytes.WriteWord(range.User.handleOrPtr, (ushort)newPosition);
            }
        }
Exemplo n.º 4
0
        public LocalHeap(GlobalHeap globalHeap, ushort globalHandle, ushort baseOffset, ushort maxSize)
        {
            _globalHeap   = globalHeap;
            _globalHandle = globalHandle;

            // Dont allocate at zero
            if (baseOffset == 0)
            {
                baseOffset = 16;
            }

            // Work out top of heap
            uint topOfHeap = _globalHeap.Size(globalHandle);
            uint heapLimit = baseOffset + (uint)(maxSize == 0 ? 0x10000 : maxSize);

            if (heapLimit > topOfHeap)
            {
                heapLimit = topOfHeap;
            }

            _allocator      = new RangeAllocator <LocalAllocation>((int)heapLimit);
            _freeHandles    = new List <ushort>();
            _handleOrPtrMap = new Dictionary <ushort, LocalAllocation>();

            var reservedPage = _allocator.Alloc(baseOffset, false, false);

            reservedPage.User = new LocalAllocation()
            {
                flags       = Win16.LMEM_FIXED,
                handleOrPtr = 0,
                range       = reservedPage,
            };

            _allocator.MoveListener = this;
            _baseOffset             = baseOffset;
        }