defaultallocator.java

来自「这个是perst-269.zip下面的SOURCECODE,和大家分享了。」· Java 代码 · 共 37 行

JAVA
37
字号
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 + =
减小字号Ctrl + -
显示快捷键?