Initialize the buffer by using allocator(size) to allocate a buffer. Optionally, set an upper limit for the buffer size.
(self, allocator, size=4096, limit=None)
| 17 | """Requested buffer size {} is above the limit of {}.""" |
| 18 | |
| 19 | def __init__(self, allocator, size=4096, limit=None): |
| 20 | """ |
| 21 | Initialize the buffer by using allocator(size) to allocate a buffer. |
| 22 | Optionally, set an upper limit for the buffer size. |
| 23 | """ |
| 24 | assert callable(allocator), "must give alloc(size) function as first param" |
| 25 | assert limit is None or size <= limit, "initial size must be <= limit" |
| 26 | self.allocator = allocator |
| 27 | self.limit = limit |
| 28 | self.resize(size, init=True) |
| 29 | |
| 30 | def __len__(self): |
| 31 | return len(self.buffer) |