Allocator
(capacity)¶Buffer space allocation implementation.
Constructor:
__init__
(capacity)¶Create an allocator for a buffer of the specified capacity.
Parameters: | capacity (int) – Maximum size of the buffer. |
---|
Methods:
alloc
(size)Allocate memory in the buffer. dealloc
(start, size)Free a region of the buffer. get_allocated_regions
()Get a list of (aggregate) allocated regions. get_fragmentation
()Return fraction of free space that is not expandable. get_fragmented_free_size
()Returns the amount of space unused, not including the final free block. get_free_size
()Return the amount of space unused. get_usage
()Return fraction of capacity currently allocated. realloc
(start, size, new_size)Reallocate a region of the buffer. set_capacity
(size)Resize the maximum buffer size.
Allocator.
alloc
(size)¶Allocate memory in the buffer.
Raises AllocatorMemoryException if the allocation cannot be fulfilled.
Parameters: | size (int) – Size of region to allocate. |
---|---|
Return type: | int |
Returns: | Starting index of the allocated region. |
Allocator.
dealloc
(start, size)¶Free a region of the buffer.
Parameters: |
|
---|
Allocator.
get_allocated_regions
()¶Get a list of (aggregate) allocated regions.
The result of this method is (starts, sizes)
, where starts
is
a list of starting indices of the regions and sizes
their
corresponding lengths.
Return type: | (list, list) |
---|
Allocator.
get_fragmentation
()¶Return fraction of free space that is not expandable.
Return type: | float |
---|
Allocator.
get_fragmented_free_size
()¶Returns the amount of space unused, not including the final free block.
Return type: | int |
---|
Allocator.
get_free_size
()¶Return the amount of space unused.
Return type: | int |
---|
Allocator.
get_usage
()¶Return fraction of capacity currently allocated.
Return type: | float |
---|
Allocator.
realloc
(start, size, new_size)¶Reallocate a region of the buffer.
This is more efficient than separate dealloc and alloc calls, as the region can often be resized in-place.
Raises AllocatorMemoryException if the allocation cannot be fulfilled.
Parameters: |
|
---|
Allocator.
set_capacity
(size)¶Resize the maximum buffer size.
The capaity cannot be reduced.
Parameters: | size (int) – New maximum size of the buffer. |
---|