def METHOD_NAME(self, size, init=False):
    """
    resize the buffer - to avoid frequent reallocation, we usually always grow (if needed).
    giving init=True it is possible to first-time initialize or shrink the buffer.
    if a buffer size beyond the limit is requested, raise Buffer.MemoryLimitExceeded (OSError).
    """
    size = int(size)
    if self.limit is not None and size > self.limit:
        raise Buffer.MemoryLimitExceeded(size, self.limit)
    if init or len(self) < size:
        self.buffer = self.allocator(size)