MCPcopy Create free account
hub / github.com/ZeroIntensity/pointers.py / malloc

Function malloc

src/pointers/malloc.py:108–130  ·  view source on GitHub ↗

Allocate memory of a given size. Args: size: Allocation size. Returns: Pointer to allocated memory. Raises: AllocationError: Raised when allocation fails, presumably due to no memory. Example: ```py ptr = malloc(1) ```

(size: int)

Source from the content-addressed store, hash-verified

106
107
108def malloc(size: int) -> AllocatedPointer[Any]:
109 """Allocate memory of a given size.
110
111 Args:
112 size: Allocation size.
113
114 Returns:
115 Pointer to allocated memory.
116
117 Raises:
118 AllocationError: Raised when allocation fails, presumably due to no memory.
119
120 Example:
121 ```py
122 ptr = malloc(1)
123 ```
124 """ # noqa
125 mem = c_malloc(size)
126
127 if not mem:
128 raise AllocationError("failed to allocate memory")
129
130 return AllocatedPointer(mem, size)
131
132
133def free(target: BaseAllocatedPointer):

Callers 2

_Function · 0.90
malloc_example.pyFile · 0.90

Calls 3

c_mallocFunction · 0.85
AllocationErrorClass · 0.85
AllocatedPointerClass · 0.85

Tested by 1

_Function · 0.72