Public Methods |
struct Buffer* | Buffer_ctor (struct Buffer *ptr_buffer, size_t size, size_t increment) |
struct Buffer* | Buffer_ctor_Ex (struct Buffer *ptr_buffer, struct Buffer *templ) |
void | Buffer_store (struct Buffer *ptr_buffer, void *ptr_data, size_t offset, size_t length) |
void | Buffer_store_string (struct Buffer *ptr_buffer, char *str, size_t offset) |
void* | Buffer_load (struct Buffer *ptr_buffer, void *ptr_data, size_t offset, size_t length) |
char* | Buffer_load_string (struct Buffer *ptr_buffer, char *str, size_t offset, size_t length) |
size_t | Buffer_get_size (struct Buffer *ptr_buffer) |
size_t | Buffer_get_allocated_size (struct Buffer *ptr_buffer) |
void | Buffer_compact (struct Buffer *ptr_buffer) |
bool | Buffer_set_size (struct Buffer *ptr_buffer, size_t size) |
void | Buffer_free (struct Buffer *ptr_buffer) |
bool | Buffer_ensure_size (struct Buffer *ptr_buffer, size_t test_size) |
char | Buffer_get_char (struct Buffer *ptr_buffer, size_t offset) |
void | Buffer_set_char (struct Buffer *ptr_buffer, size_t offset, char data) |
int | Buffer_get_int (struct Buffer *ptr_buffer, size_t offset) |
void | Buffer_set_int (struct Buffer *ptr_buffer, size_t offset, int data) |
long | Buffer_get_long (struct Buffer *ptr_buffer, size_t offset) |
void | Buffer_set_long (struct Buffer *ptr_buffer, size_t offset, long data) |
bool | Buffer_is_locked (struct Buffer *ptr_buffer) |
void* | Buffer_lock (struct Buffer *ptr_buffer) |
void | Buffer_unlock (struct Buffer *ptr_buffer) |
void | Buffer_dtor (struct Buffer *ptr_buffer, int) |
This object provides a movable memory buffer that can be dynamically created, resized, and used as a plain memory block or as storage with access helpers.
For CyOS, buffers are better than plain dynamic memory - allocated chunks because they can be locked and unlocked. While they are unlocked, the OS may move them in order to organize memory more efficiently, and may even drop the buffer to the flash so it may be used as a kind of virtual memory.
The best way to work with this object is to keep the buffer unlocked and use access helpers methods Buffer_load, Buffer_load_string, Buffer_store, Buffer_store_string, Buffer_get_byte, Buffer_set_byte, Buffer_get_char, Buffer_set_char, Buffer_get_int, Buffer_set_int, Buffer_get_long, Buffer_set_long and so on.
The difference between store_ and set_ methods is that store_* automatically resizes the buffer to fit the size required, while set_ methods check and treat " out of bounds " as an error.
Please note that the offsets for all helpers get_* and set_* are ALWAYS IN BYTES. The Buffers have a size/increment/capacity space strategy. This means that when a Buffer needs to expand its storage, it uses an increment and stores both the actual data size and the current capacity to minimize the load on the dynamic memory subsystem.
Use Buffer_set_size, Buffer_ensure_size and Buffer_compact methods to manage the buffer's capacity.