defaultallocator.cs
来自「Perst开源实时数据库」· CS 代码 · 共 42 行
CS
42 行
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 + =
减小字号Ctrl + -
显示快捷键?