CDI SDK
SDK for transporting chunks of data reliably and with low latency using a polled mode network driver.
|
CDI Pool provides a collection of generic functions for managing memory use. Using CDI Pool functions, users can pre-allocate a memory block sized to fit a given number of items of the user's data type, then reserve and free items from the pool as needed. Pools can be created and zeroed-out, and optionally the contents of each pool item can be initialized using a user-provided callback function. Finally, pools can be set up to grow automatically when they are not large enough to accommodate a new request, and can error out when a provided grow limit is reached.
Refer to cdi_pool_api.h for API details.
As outlined in the API, several functions exist for creating pools. The following example demonstrates the instructions needed to generate a pool of transmit buffers from a pre-allocated buffer space. In this example, the pool function CdiPoolCreateUsingExistingBuffer() is used to allocate payload buffers within the adapter buffer that is reserved when the adapter is initialized.
Set defines and initialize variables. Use the CdiPoolHandle type to create a pool handle.
Initialize the adapter interface, and then use the returned ret_tx_buffer_ptr buffer pointer to create a pool of payload buffers which the application's transmit code can pull from later. The pool create function will return the actual number of bytes needed in buffer_bytes_size_needed_ptr.
Whenever a payload is to be sent, get a payload buffer from the pool. If the pool get fails, use pool functions to get information about the pool to use in a log message.
In the case of transmit buffers, the buffers will be used by the SDK until the Tx Callback occurs. Pool items should be put back into the pool during the application's Tx Callback function. Buffers are to be returned to the pool using CdiPoolPut().
When the application is shutting down, destroy the pool. Under normal management and use of pool gets and puts, the call to CdiPoolPutAll() is unnecessary, and would probably be masking a coding error, but it can be used as a safeguard if desired.