📄 defaultallocator.java
字号:
package org.garret.perst.impl;
import org.garret.perst.*;
public class DefaultAllocator extends Persistent implements CustomAllocator {
public DefaultAllocator(Storage storage) {
super(storage);
}
protected DefaultAllocator() {}
public long allocate(long size) {
return ((StorageImpl)getStorage()).allocate(size, 0);
}
public long reallocate(long pos, long oldSize, long newSize) {
StorageImpl db = (StorageImpl)getStorage();
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)getStorage()).cloneBitmap(pos, size);
}
public void commit() {}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -