Cross-platform C SDK logo

Cross-platform C SDK

Buffers

❮ Back
Next ❯
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 (...)
Bufferbuffer_read (...)
voidbuffer_destroy (...)
uint32_tbuffer_size (...)
byte_t*buffer_data (...)
const byte_t*buffer_const (...)
voidbuffer_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.

Representation of a block of memory.
Figure 1: Dynamic memory block.
❮ Back
Next ❯

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 NULL after the destruction.


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.

❮ Back
Next ❯