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 (...) |
Buffer | buffer_read (...) |
void | buffer_destroy (...) |
uint32_t | buffer_size (...) |
byte_t* | buffer_data (...) |
const byte_t* | buffer_const (...) |
void | buffer_write (...) |
Buffer objects are simply dynamically reserved blocks of memory stored in the Heap Segment (Figure 1). They are useful for sharing generic data between different functions or threads. For the latter case, they must be protected by a Mutex if multiple concurrent threads could access it (they are not thread-safe). They are fixed size. Once created they cannot 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.
- Use buffer_read to read from a stream.
- Use buffer_write to write to a stream.
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_read ()
Read a buffer from a stream.
Buffer buffer_read(Stream *stream);
stream | An input stream. |
Return
The 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.
buffer_write ()
Writes a buffer to a stream.
void buffer_write(Stream *stream, const Buffer *buffer);
stream | An output stream. |
buffer | The buffer. |