BUF_alloc
Application Program Interface
2-19
C Interface
Syntax
bufaddr = BUF_alloc(buf);
Parameters
BUF_Handle buf;
/* buffer pool object handle */
Return Value
Ptr
bufaddr;
/* pointer to free buffer */
Reentrant
yes
Description
BUF_alloc allocates a fixed-size buffer from the specified buffer pool and
returns a pointer to the buffer. BUF_alloc does not initialize the allocated
buffer space.
The buf parameter is a handle to identify the buffer pool object, from
which the fixed size buffer is to be allocated. If the buffer pool was created
dynamically, the handle is the one returned by the call to BUF_create. If
the buffer pool was created statically, the handle can be referenced as
shown in the example that follows.
If buffers are available in the specified buffer pool, BUF_alloc returns a
pointer to the buffer. If no buffers are available, BUF_alloc returns NULL.
The BUF module manages synchronization so that multiple threads can
share the same buffer pool for allocation and free operations.
The time required to successfully execute BUF_alloc is deterministic
(constant over multiple calls).
Example
extern BUF_Obj bufferPool;
BUF_Handle buffPoolHandle = &bufferPool;
Ptr buffPtr;
/* allocate a buffer */
buffPtr = BUF_alloc(buffPoolHandle);
if (buffPtr == NULL ) {
SYS_abort("BUF_alloc failed");
}
See Also
BUF_alloc
Allocate a fixed-size buffer from a buffer pool