⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 defaultallocator.cs

📁 Perst开源实时数据库
💻 CS
字号:
namespace Perst.Impl
{
    using System;
    using Perst;

    public class DefaultAllocator : Persistent, CustomAllocator 
    { 
        public DefaultAllocator(Storage storage) 
            : base(storage)
        {
        }
    
        protected DefaultAllocator() {}

        public long Allocate(long size) 
        { 
            return ((StorageImpl)Storage).allocate(size, 0);
        }

        public long Reallocate(long pos, long oldSize, long newSize) 
        {
            StorageImpl db = (StorageImpl)Storage;
            if (((newSize + StorageImpl.dbAllocationQuantum - 1) & ~(StorageImpl.dbAllocationQuantum-1))
                > ((oldSize + StorageImpl.dbAllocationQuantum - 1) & ~(StorageImpl.dbAllocationQuantum-1)))
            { 
                long newPos = db.allocate(newSize, 0);
                db.cloneBitmap(pos, oldSize);
                db.free(pos, oldSize);
                pos = newPos;
            }
            return pos;
        }

        public void Free(long pos, long size) 
        { 
            ((StorageImpl)Storage).cloneBitmap(pos, size);
        }
        
        public void Commit() {}
    }      
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -