Skip to main content

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 region
  • BEST_FIT allocation will allocate new regions into the free region which will create the smallest leftover memory range

Metadata

Release files for virtual-allocator 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for virtual-allocator 0.0.3
File Size Uploaded
virtual_allocator-0.0.3.tar.gz 28.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for virtual-allocator 0.0.3
File Interpreter ABI Platform
virtual_allocator-0.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 33.8 kB

Release files / virtual_allocator-0.0.3.tar.gz

Download URL virtual_allocator-0.0.3.tar.gz
Size 28.2 kB
Tags Source
SHA-256 checksum
How to use checksums
1e15eb18d22433c743b901b0596e6933580512638d0466b380537d42e16ca291
BLAKE2b-256 checksum
How to use checksums
12f3ad48725628501d2f7815b2cf23b67b607f2e06946f7ad14c92654b687b29
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.8.22

Release files / virtual_allocator-0.0.3-py3-none-any.whl

Download URL virtual_allocator-0.0.3-py3-none-any.whl
Size 5.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9ee5e68f842b100e5153de5a27d5a5bcd8445bf92afa77a0b012cf8075151661
BLAKE2b-256 checksum
How to use checksums
f900660c45a538b156e59b790829b66a7ee74e94081cd3c461120fb3045a4b16
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.8.22

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files

0.0.2

2 release files

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page