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

Class AllocatedPointer

src/pointers/malloc.py:19–105  ·  view source on GitHub ↗

Pointer to allocated memory.

Source from the content-addressed store, hash-verified

17
18
19class AllocatedPointer(IterDereferencable[T], BaseAllocatedPointer[T]):
20 """Pointer to allocated memory."""
21
22 def __init__(
23 self,
24 address: int,
25 size: int,
26 assigned: bool = False,
27 parent: AllocatedPointer[T] | None = None,
28 ) -> None:
29 """
30 Args:
31 address: Address of the allocated memory.
32 size: Size of the allocated memory.
33 assigned: Whether an object is currently inside the memory.
34 """
35 self._address = address
36 self._size = size
37 self._freed = False
38 self._assigned = assigned
39 self._parent: AllocatedPointer[T] | None = parent
40
41 def _indexed(self, amount: int) -> AllocatedPointer[T]:
42 return AllocatedPointer(
43 self.ensure() + amount,
44 self.size - amount,
45 self.assigned,
46 parent=self._parent,
47 )
48
49 def _get_parent(self) -> AllocatedPointer[T]:
50 parent = self
51
52 while parent._parent:
53 parent = parent._parent
54
55 return parent
56
57 @property
58 def freed(self) -> bool:
59 return self._get_parent()._freed
60
61 @freed.setter
62 def freed(self, value: bool) -> None:
63 self._get_parent()._freed = value
64
65 @property
66 def address(self) -> Optional[int]:
67 return self._address
68
69 @address.setter
70 def address(self, value: int) -> None:
71 self._address = value
72
73 def __repr__(self) -> str:
74 return f"AllocatedPointer(address={self.address}, size={self.size})"
75
76 def __add__(self, amount: int) -> AllocatedPointer[T]:

Callers 2

_indexedMethod · 0.85
mallocFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected