Python allocator for a virtual memory range
Project description
virtual-allocator
Python allocator for a virtual memory range. This package only implements the allocation of a memory range, the actual memory access must be implemented separately. So no use-after-free errors can be handled.
The allocator implements the allocate
, free
and resize
methods which each return a new MemoryRegion
object.
from virtual_allocator import AllocationPolicy, Allocator, MemoryRange
alloc = Allocator(
address=0,
size=256,
block_size=16,
alignment=32,
allocation_policy=AllocationPolicy.BEST_FIT
)
mem_ranges = [alloc.allocate(64) for _ in range(3)]
assert mem_ranges == [
MemoryRange(address=0, size=64, is_free=False, padding=0),
MemoryRange(address=64, size=64, is_free=False, padding=0),
MemoryRange(address=128, size=64, is_free=False, padding=0),
MemoryRange(address=196, size=64, is_free=True, padding=0),
]
alloc.free(mem_ranges[1])
assert mem_ranges == [
MemoryRange(address=0, size=64, is_free=False, padding=0),
MemoryRange(address=64, size=64, is_free=True, padding=0),
MemoryRange(address=128, size=64, is_free=False, padding=0),
MemoryRange(address=196, size=64, is_free=True, padding=0),
]
Allocation policies
The allocator class supports two allocation policies, FIRST_FIT
and BEST_FIT
.
FIRST_FIT
allocation allocates new regions into the lowest free regionBEST_FIT
allocation will allocate new regions into the free region which will create the smallest leftover memory range
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file virtual-allocator-0.0.2.tar.gz
.
File metadata
- Download URL: virtual-allocator-0.0.2.tar.gz
- Upload date:
- Size: 6.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce7e6fd5620e18819e22412ae6fdac46fd37037f8232be0e9a1e3d244a25596e |
|
MD5 | 135a34eec8d33b12c93f4db9a08761b8 |
|
BLAKE2b-256 | 6a69e0a061d6176e01782ba16cc0e309886a78f4c499f3a19941209d1871e729 |
File details
Details for the file virtual_allocator-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: virtual_allocator-0.0.2-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b657ae39de78b9f7bd331088410a0a5976e12d37d42ae2a95e659435f9f94439 |
|
MD5 | f92690b17f0215d4b6699a7191616eae |
|
BLAKE2b-256 | 8762ff568bef8c6fb1e2340e796453cff03c6e04b5b700b6212af5393b83e9d8 |