Untitled

 avatar
unknown
plain_text
4 months ago
1.9 kB
9
Indexable
/**
 * Handle used to reference data stored in the memory manager.
 * A handle records the starting index in the memory pool and
 * the allocated block size, as well as the actual data length
 * for the record.
 * 
 * The memory manager can use (start, size) to locate the block
 * and uses dataLength to avoid truncating or over-reading when
 * returning the stored bytes.
 * 
 * @author Leguejou Awunganyi
 * @author Ishita Punna
 * @version 2026-02-08
 */
public class Handle {

    /**
     * Starting index of the allocated block in the memory pool.
     */
    private int start;

    /**
     * Size in bytes of the allocated block (a power-of-two buddy size).
     */
    private int size;

    /**
     * Actual length in bytes of the record stored in this block.
     */
    private int dataLength;

    /**
     * Create a new handle for a record stored in the memory manager.
     *
     * @param startIndex
     *        starting index of the allocated block in the memory pool
     * @param blockSize
     *        total size in bytes of the allocated block
     * @param recordLength
     *        actual length in bytes of the record data
     */
    public Handle(int startIndex, int blockSize, int recordLength) {
        start = startIndex;
        size = blockSize;
        dataLength = recordLength;
    }

    /**
     * Get the starting index of this block in the memory pool.
     *
     * @return start index in bytes
     */
    public int getStart() {
        return start;
    }

    /**
     * Get the total size of the allocated block.
     *
     * @return block size in bytes
     */
    public int getSize() {
        return size;
    }

    /**
     * Get the actual length of the record stored in this block.
     *
     * @return record length in bytes
     */
    public int getDataLength() {
        return dataLength;
    }
}
Editor is loading...
Leave a Comment