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)
| 106 | |
| 107 | |
| 108 | def 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 | |
| 133 | def free(target: BaseAllocatedPointer): |