malloc module

class src.core.malloc.MemoryManager(limit_mb)

Bases: object

A class to manage memory allocation with a specified limit.

The MemoryManager class allows for tracking and limiting memory allocation within a program. It provides methods to allocate and deallocate memory, ensuring that the allocated memory does not exceed a predefined limit. The class also allows querying the currently allocated memory and the remaining available memory.

limit

The memory limit in bytes.

Type:

int

allocated_memory

The total amount of currently allocated memory in bytes.

Type:

int

allocate(size)

Allocates the given amount of memory.

Args: size (int): The amount of memory to allocate in bytes.

Raises: MemoryError: If the allocation exceeds the memory limit.

deallocate(size)

Deallocates the given amount of memory.

Args: size (int): The amount of memory to deallocate in bytes.

get_allocated_memory()

Returns the total allocated memory.

Returns: int: The total allocated memory in bytes.

get_remaining_memory()

Returns the remaining memory.

Returns: int: The remaining memory in bytes.