aboutsummaryrefslogtreecommitdiff
path: root/buffer.h
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-07-12 21:32:44 +0200
committerdec05eba <dec05eba@protonmail.com>2020-07-12 21:32:44 +0200
commitdfad8a8016426d7fe198dc32973b01a1e075142e (patch)
tree1ba7312e0a3d5dbb1942088165e338ffd25af034 /buffer.h
parent4f9c16f821af54110889c01eed0cb6bbf9eb9ce2 (diff)
Starting on conversion to c. Program exec, buffers..
Diffstat (limited to 'buffer.h')
-rw-r--r--buffer.h30
1 files changed, 30 insertions, 0 deletions
diff --git a/buffer.h b/buffer.h
new file mode 100644
index 0000000..a8c1940
--- /dev/null
+++ b/buffer.h
@@ -0,0 +1,30 @@
+#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 {
+ void *data;
+ size_t size;
+ size_t capacity;
+} Buffer;
+
+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);
+
+#endif