def METHOD_NAME(self, numel):
    if self.current_buffer_index == INVALID_BUFFER_INDEX:
        self._allocate_buffer()
        return
    if not self._get_current_buffer().has_space(numel):
        if len(self.free_buffer_index) > 0:
            self._flush_ready_buffers()
        else:
            self._flush_buffers_until_complete()
        self._allocate_buffer()