public class Allocator
extends java.lang.Object
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.
Constructor and Description |
---|
Allocator(long heapBase,
long heapSize) |
Modifier and Type | Method and 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
|
public void declareAllocated(long address, long size)
address
- size
- public long alloc(long size)
size
- public void free(long address, long size)