Skip to main content

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

virtual_allocator-0.0.3.tar.gz (28.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

virtual_allocator-0.0.3-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file virtual_allocator-0.0.3.tar.gz.

File metadata

  • Download URL: virtual_allocator-0.0.3.tar.gz
  • Upload date:
  • Size: 28.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.8.22

File hashes

Hashes for virtual_allocator-0.0.3.tar.gz
Algorithm Hash digest
SHA256 1e15eb18d22433c743b901b0596e6933580512638d0466b380537d42e16ca291
MD5 f7b45479ef4fa4e8b51905cb0cb033a9
BLAKE2b-256 12f3ad48725628501d2f7815b2cf23b67b607f2e06946f7ad14c92654b687b29

See more details on using hashes here.

File details

Details for the file virtual_allocator-0.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for virtual_allocator-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9ee5e68f842b100e5153de5a27d5a5bcd8445bf92afa77a0b012cf8075151661
MD5 d86fb464d3f8f9f88b712a445f0cbcd0
BLAKE2b-256 f900660c45a538b156e59b790829b66a7ee74e94081cd3c461120fb3045a4b16

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page