Resize the buffer. To avoid frequent reallocation, we usually grow (if needed). By giving init=True it is possible to initialize for the first time or shrink the buffer. If a buffer size beyond the limit is requested, raise Buffer.MemoryLimitExceeded (OSError).
(self, size, init=False)
| 31 | return len(self.buffer) |
| 32 | |
| 33 | def resize(self, size, init=False): |
| 34 | """ |
| 35 | Resize the buffer. To avoid frequent reallocation, we usually grow (if needed). |
| 36 | By giving init=True it is possible to initialize for the first time or shrink the buffer. |
| 37 | If a buffer size beyond the limit is requested, raise Buffer.MemoryLimitExceeded (OSError). |
| 38 | """ |
| 39 | size = int(size) |
| 40 | if self.limit is not None and size > self.limit: |
| 41 | raise Buffer.MemoryLimitExceeded(size, self.limit) |
| 42 | if init or len(self) < size: |
| 43 | self.buffer = self.allocator(size) |
| 44 | |
| 45 | def get(self, size=None, init=False): |
| 46 | """ |
no outgoing calls