Class Allocator
- java.lang.Object
-
- org.cakelab.blender.io.block.alloc.Allocator
-
public class Allocator extends java.lang.Object
The allocator manages regions of allocated and free memory (chunks).Purpose of the allocator is basically to determine an appropriate address for a new block. The allocator will not allocate memory.
The allocator implemented here uses a simple algorithm with a single linked list of allocated and free chunks. To find free chunks of appropriate size it uses the next fit algorithm. Neighbouring chunks of the same type (either allocated or free) get merged to reduce the amount of chunks in the list.
- Author:
- homac
-
-
Constructor Summary
Constructors Constructor Description Allocator(long heapBase, long heapSize)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description long
alloc(long size)
Allocate memory of given size and return its address.void
declareAllocated(long address, long size)
This method is used during initialisation only to declare regions of memory to be allocated beforehand.void
free(long address, long size)
free the given size of memory at the given address
-
-
-
Method Detail
-
declareAllocated
public void declareAllocated(long address, long size)
This method is used during initialisation only to declare regions of memory to be allocated beforehand. It defines a partition (address, size) to be allocated.- Parameters:
address
-size
-
-
alloc
public long alloc(long size)
Allocate memory of given size and return its address.- Parameters:
size
-- Returns:
- address of allocated area
-
free
public void free(long address, long size)
free the given size of memory at the given address
-
-