Buffers
This page has been automatically translated using the Google Translate API services. We are working on improving texts. Thank you for your understanding and patience.
Generic memory blocks, dynamically reserved.
Functions
Buffer* | buffer_create (...) |
Buffer* | buffer_with_data (...) |
void | buffer_destroy (...) |
uint32_t | buffer_size (...) |
byte_t* | buffer_data (...) |
const byte_t* | buffer_const (...) |
Buffer objects are simply dynamically stored memory blocks and stored in the Heap Segment. They are useful for sharing generic data between different functions or threads. For the latter case, they must be protected by a Mutex if several threads can access it concurrently (they are not thread-safe). They are of fixed size. Once created, they can not be resized, although they can be rewritten as many times as necessary.
- Use buffer_create to create a dynamic memory block.
- Use buffer_destroy to free up a block of dynamic memory.
- Use buffer_data to get a pointer to the memory block.
buffer_create ()
Create a new buffer.
Buffer* buffer_create(const uint32_t size);
size | Buffer size in bytes. |
Return
The new buffer.
buffer_with_data ()
Create a new buffer and initialize it.
Buffer* buffer_with_data(const byte_t *data, const uint32_t size);
data | Data to initialize the buffer. |
size | Buffer size in bytes. |
Return
The new buffer.
buffer_destroy ()
Destroy the buffer.
void buffer_destroy(Buffer **buffer);
buffer | The buffer. It will be set to |
buffer_size ()
Gets the size of the buffer.
uint32_t buffer_size(const Buffer *buffer);
buffer | Buffer. |
Return
The size of the buffer in bytes.
buffer_data ()
Gets a pointer to the contents of the buffer.
byte_t* buffer_data(Buffer *buffer);
buffer | Buffer. |
Return
Pointer to the contents of the buffer that can be used to read or write.
buffer_const ()
Get a const pointer to the contents of the buffer.
const byte_t* buffer_const(const Buffer *buffer);
buffer | Buffer. |
Return
Pointer to the content of the buffer that can be used for reading only.