Obtain a writable block of contiguous bytes at the end of this queue, allocating more space if necessary. methodset Allocation
Synopsis
Declared in <folly/io/IOBufQueue.h>
std::pair<void*, std::size_t>
preallocate(
std::size_t min,
std::size_t newAllocationSize,
std::size_t max = std::numeric_limits<std::size_t>::max());
Description
The amount of space reserved will be at least min. If min contiguous space is not available at the end of the queue, and IOBuf with size newAllocationSize is appended to the chain and returned. The actual available space may be larger than newAllocationSize, but will be truncated to max, if specified.
If the caller subsequently writes anything into the returned space, it must call the postallocate() method.
|
Note
|
The point of the preallocate()/postallocate() mechanism is to support I/O APIs such as AsyncSocket::ReadCallback that request a buffer from the application and then, in a later callback, tell the application how much of the buffer they have filled with data. |
Return Value
The starting address of the block and the length in bytes.
Parameters
Name |
Description |
min |
The minimum amount of contiguous space to reserve. |
newAllocationSize |
The size of a new buffer if one is allocated. |
max |
The maximum amount of space to return. |
Created with MrDocs