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.
|
Resizes storage to the current data size.
|
|
Create an empty buffer of a specified data_size.
|
|
Creates a copy of the existing buffer.
|
|
Unlocks and frees a previously locked buffer.
|
|
Reallocates and copies the buffer's contents, if needed.
|
|
Clears the buffer and frees its storage.
|
|
Returns the size of the allocated space (current capacity that may be bigger than Buffer_get_size()).
|
|
Reads char at the specified 'offset'.
|
|
Reads the int value at the specified 'offset'.
|
|
Reads the long value at the specified 'offset'.
|
|
Returns the size of the data in the buffer.
|
|
Returns lock state (locked or unlocked).
|
|
Loads 'length' bytes from the Buffer, starting at the specified 'offset'.
|
|
Loads null terminated string.
|
|
Locks storage and returns the pointer to it's area.
|
|
Writes char value 'data' at the specified 'offset'.
|
|
Writes the int 'data' at the specified 'offset'.
|
|
Writes the long value 'data' at the specified 'offset'.
|
|
Sets the size.
|
|
Stores some data at the specified offset.
|
|
Stores a null-terminated string into the buffer.
|
|
Unlocks the buffer's storage.
|
Copyright © 2001 Cybiko, Inc. All rights reserved. | More information... |