Allocation¶
- class memobj.allocation.Allocation(address: int, process: Process, size: int)[source]¶
Bases:
object
- class memobj.allocation.Allocator(process: Process)[source]¶
Bases:
object- with Allocator(process) as allocator:
- with allocator.allocate() as allocation:
# do something with allocation
allocation = allocator.allocate()
- allocate(size: int, *, preferred_start: int | None = None) Allocation[source]¶
Allocates a block of memory for the process.
Allocates a specified block of memory for the associated process, keeping track of the allocation for management purposes. The allocated memory is represented as an Allocation object and is appended to the list of current allocations.
- Parameters:
size (int) – The size of the memory block to allocate in bytes.
preferred_start – The preferred start address of the allocation
- Returns:
An object representing the allocated memory block.
- Return type:
- close()[source]¶
Closes the allocator, ensuring all current allocations are properly freed and the allocator is set to a closed state. This method prevents further use of the allocator by marking it as closed. If the allocator is already closed, an error will be raised.
- Raises:
ValueError – If the allocator is already closed before the invocation of this method.