NetBurner 3.5.6
PDF Version
Buffers - System Buffer Pool

Topics

 Buffer Ownership States
 
 Buffer State Flags
 

Classes

struct  pool_buffer
 Main buffer structure for network and serial communication. More...
 
class  buffer_list
 Doubly-linked list management for buffers. More...
 
class  fifo_buffer_storage
 FIFO buffer storage using linked pool buffers. More...
 
class  SMPoolPtr
 Smart pointer wrapper for automatic buffer management. More...
 

Functions

PoolPtr GetBuffer ()
 Allocate a software buffer for general use.
 
PoolPtr GetFastBuffer ()
 Allocate a software buffer, preferring the fast memory pool.
 
void FreeBuffer (PoolPtr nbuf)
 Free a buffer and return it to the unused pool.
 
void FreeBufferList (PoolPtr nbuf)
 Free a linked list of buffers.
 
void IncUsageCount (PoolPtr pp)
 Increment the usage count of a buffer.
 
uint16_t GetFreeCount ()
 Returns the number of free buffers in the system. Buffers are used for both serial and network interfaces.
 
void InitBuffers ()
 Initialize the buffer system.
 
void ShowBuffer (PoolPtr p)
 Display buffer contents and state information.
 

Detailed Description

#include< buffers.h>


Functions associated with the buffers allocated for use by network interfaces and serial ports. If a system runs out of buffers it will no longer be able to send or receive network data.

Function Documentation

◆ FreeBuffer()

void FreeBuffer ( PoolPtr nbuf)

#include <buffers.h>

Free a buffer and return it to the unused pool.

Decrements the buffer's usage count and returns it to the free pool when the count reaches zero. This allows safe sharing of buffers between multiple system components.

Parameters
nbufBuffer to free
See also
GetBuffer(), IncUsageCount()

◆ FreeBufferList()

void FreeBufferList ( PoolPtr nbuf)

#include <buffers.h>

Free a linked list of buffers.

Frees a chain of buffers linked by their pNextFifo_El pointers. Each buffer in the list will be returned to the unused pool.

Parameters
nbufFirst buffer in the linked list to free
See also
FreeBuffer()

◆ GetBuffer()

PoolPtr GetBuffer ( )

#include <buffers.h>

Allocate a software buffer for general use.

Allocates a buffer from the system buffer pool for use by application software. The buffer will be marked with ownership state BO_SOFTWARE.

Returns
Pointer to allocated buffer, or NULL if no buffers available
See also
FreeBuffer(), GetFastBuffer()

◆ GetFastBuffer()

PoolPtr GetFastBuffer ( )

#include <buffers.h>

Allocate a software buffer, preferring the fast memory pool.

Similar to GetBuffer(), but attempts to allocate from the fast buffer pool first before falling back to the standard pool. Fast buffers may provide better performance for time-critical operations.

Returns
Pointer to allocated buffer, or NULL if no buffers available
See also
GetBuffer(), FreeBuffer()

◆ GetFreeCount()

uint16_t GetFreeCount ( )

#include <buffers.h>

Returns the number of free buffers in the system. Buffers are used for both serial and network interfaces.

This function returns the number of free pool buffers, which are used for network and serial communication. The maximum number of buffers is defined in \nburn\nbrtos\include\constants.h:

#define BUFFER_POOL_SIZE (128)

The size of each buffer is defined as:

#define ETHER_BUFFER_SIZE 1548

If the number of free buffers reaches zero, then no further network communication will be possible until some buffers are freed. This is a good function to use as a debug tool for detecting buffer leaks in your application.

Serial ports also use buffers, which are allocated in constants.h:

#define SERIAL_TX_BUFFERS (2)
#define SERIAL_RX_BUFFERS (2)

Each serial port buffer is equal in size to an Ethernet buffer.

Returns
The number of free buffers in the system.

◆ IncUsageCount()

void IncUsageCount ( PoolPtr pp)

#include <buffers.h>

Increment the usage count of a buffer.

Increases the reference count for shared buffer usage. The buffer will not be freed until FreeBuffer() is called once for each reference (usage count reaches zero).

Parameters
ppBuffer to increment usage count
See also
FreeBuffer()

◆ InitBuffers()

void InitBuffers ( )

#include <buffers.h>

Initialize the buffer system.

Sets up the buffer pools and free lists. This function is called during system initialization and should not be called by application code.

See also
GetFreeCount()

◆ ShowBuffer()

void ShowBuffer ( PoolPtr p)

#include <buffers.h>

Display buffer contents and state information.

Prints detailed information about a buffer including its state, size, and data contents to stdout. Useful for debugging.

Parameters
pBuffer to display