Pointer to an allocated array.
| 24 | |
| 25 | |
| 26 | class AllocatedArrayPointer(BaseAllocatedPointer[T]): |
| 27 | """Pointer to an allocated array.""" |
| 28 | |
| 29 | def __init__( |
| 30 | self, |
| 31 | address: int, |
| 32 | chunks: int, |
| 33 | chunk_size: int, |
| 34 | current_index: int, |
| 35 | chunk_store: Optional[Dict[int, "AllocatedArrayPointer[T]"]] = None, |
| 36 | freed: bool = False, |
| 37 | origin_address: Optional[int] = None, |
| 38 | ) -> None: |
| 39 | self._origin_address = origin_address or address |
| 40 | self._address = address |
| 41 | self._size = chunk_size |
| 42 | self._current_index = current_index |
| 43 | self._chunks = chunks |
| 44 | self._chunk_store = chunk_store or {0: self} |
| 45 | self._assigned = True |
| 46 | self._tracked = False |
| 47 | self._freed = freed |
| 48 | |
| 49 | if chunk_store: |
| 50 | self._chunk_store[self.current_index] = self |
| 51 | |
| 52 | @property # type: ignore |
| 53 | def address(self) -> Optional[int]: |
| 54 | return self._address |
| 55 | |
| 56 | @property |
| 57 | def current_index(self) -> int: |
| 58 | """Current chunk index.""" |
| 59 | return self._current_index |
| 60 | |
| 61 | @property |
| 62 | def chunks(self) -> int: |
| 63 | """Number of allocated chunks.""" |
| 64 | return self._chunks |
| 65 | |
| 66 | def _get_chunk_at(self, index: int) -> "AllocatedArrayPointer[T]": |
| 67 | if index > self.chunks: |
| 68 | raise IndexError( |
| 69 | f"index is {index}, while allocation is {self.chunks}", |
| 70 | ) |
| 71 | |
| 72 | if index < 0: # for handling __sub__ |
| 73 | raise IndexError("index is below zero") |
| 74 | |
| 75 | if index not in self._chunk_store: |
| 76 | self._chunk_store[index] = AllocatedArrayPointer( |
| 77 | self._origin_address + (index * self.size), |
| 78 | self.chunks, |
| 79 | self.size, |
| 80 | index, |
| 81 | self._chunk_store, |
| 82 | self._freed, |
| 83 | self._origin_address, |
no outgoing calls
no test coverage detected