diff options
author | dec05eba <dec05eba@protonmail.com> | 2020-07-13 15:59:30 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-07-13 15:59:30 +0200 |
commit | ae0520e57267dbd866fc8cd25f66f4e6af2ac118 (patch) | |
tree | 22788688f1b588c3ad00c1ce3fe13da68b3a9382 /src/buffer.h | |
parent | a1ca82847eb356c6b85ada2ac11f38d98f6e085e (diff) |
Move c files into src directory
Diffstat (limited to 'src/buffer.h')
-rw-r--r-- | src/buffer.h | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/buffer.h b/src/buffer.h new file mode 100644 index 0000000..a50cd85 --- /dev/null +++ b/src/buffer.h @@ -0,0 +1,33 @@ +#ifndef BUFFER_H +#define BUFFER_H + +#include <stddef.h> + +/* + TODO: Optimize small size buffers by using data and size members (16 bytes on x86) + instead of heap allocation +*/ + +typedef struct Buffer Buffer; +struct Buffer { + void *data; + size_t size; + size_t capacity; +}; + +void buffer_init(Buffer *self); +void buffer_deinit(Buffer *self); + +void buffer_append(Buffer *self, const void *data, size_t size); +/* + This function changes the size of the buffer without changing the capacity + and returns the value at the back of the buffer, which is valid until @tsl_buffer_append or + @tsl_buffer_deinit is called. + The buffer size has to be larger or equal to @size. +*/ +void* buffer_pop(Buffer *self, size_t size); +void* buffer_begin(Buffer *self); +void* buffer_end(Buffer *self); +size_t buffer_get_size(Buffer *self, size_t type_size); + +#endif |