Exemple #1
0
        private StreamWriter _sw = new StreamWriter(new MemoryStream()); //@"d:\temp\gc-log.txt");

        public AutoMemoryManager(AutoMemoryManagementContext autoMemoryManagementContext, IMemoryManager underlying)
        {
            _sw.BaseStream.SetLength(0);

            _autoMemoryManagementContext = autoMemoryManagementContext;
            _underlying = underlying;

            _poolSize = _initialPoolSize;
            _pool     = underlying.Alloc(_initialPoolSize).value;

            _defaultLayout          = autoMemoryManagementContext.RuntimeGlobalAccessor.GetDefaultLayoutInfo();
            _markBitFieldInfo       = _defaultLayout.Fields[autoMemoryManagementContext.MarkBitFieldNumber];
            _realBlockSizeFieldInfo = _defaultLayout.Fields[autoMemoryManagementContext.RealBlockSizeFieldNumber];

            MMFreeBlockHeader *item = (MMFreeBlockHeader *)_pool;

            item->next = MMFreeBlockHeader.ZeroPtr;
            item->size = _poolSize - sizeof(MMFreeBlockHeader);

            _freeBlocks = item;

            _stats.currentAllocatedBlocksCount = 0;
            _stats.currentAllocatedBytes       = 0;
            _stats.currentAllBlocksCount       = 1;
            _stats.currentAvailableBytes       = _poolSize;

            _stats.totalBlocksCreated   = 1;
            _stats.totalBlocksMerged    = 0;
            _stats.totalBlocksAllocated = 0;
            _stats.totalBlocksFreed     = 0;
        }
Exemple #2
0
        private void Expand()
        {
            var newPool = _underlying.Alloc(_poolSize).value;

            if (newPool == IntPtr.Zero)
            {
                throw new OutOfMemoryException("Failed to expand memory pool");
            }

            MMFreeBlockHeader *item = (MMFreeBlockHeader *)newPool;

            item->next = MMFreeBlockHeader.ZeroPtr;
            item->size = _poolSize - sizeof(MMFreeBlockHeader);
            this.InsertFreeBlockToList(item);
        }
        private void Expand()
        {
            var poolSize         = _poolSize;
            var poolHeaderOffset = poolSize.AlignTo(Alignment);
            var newPool          = _underlyingMM.Alloc((poolHeaderOffset + sizeof(MMPool)).AlignTo(Alignment)).value;

            if (newPool == IntPtr.Zero)
            {
                throw new OutOfMemoryException("Failed to expand memory pool");
            }

            MMFreeBlockHeader *item = (MMFreeBlockHeader *)newPool;

            item->next = MMFreeBlockHeader.ZeroPtr;
            item->size = poolSize - sizeof(MMFreeBlockHeader);
            this.InsertFreeBlockToList(item);

            MMPool *poolHeader = (MMPool *)(((int)newPool) + poolHeaderOffset);

            poolHeader->next     = _pools;
            poolHeader->rangePtr = newPool;
            poolHeader->size     = poolSize;
            _pools = poolHeader;
        }
 public BlockPtr Alloc(int size)
 {
     return(_underlying.Alloc(size));
 }
Exemple #5
0
 public BlockPtr Alloc(int size)
 {
     return(_memoryManager.Alloc(size));
 }