summaryrefslogtreecommitdiffstats
path: root/example/buffer.c
diff options
context:
space:
mode:
Diffstat (limited to 'example/buffer.c')
-rw-r--r--example/buffer.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/example/buffer.c b/example/buffer.c
new file mode 100644
index 0000000..35237b2
--- /dev/null
+++ b/example/buffer.c
@@ -0,0 +1,22 @@
+// buffer.c - Example usage of buffer.h dynamic buffer
+
+#define BUFFER_IMPLEMENTATION
+#include "../include/buffer.h"
+
+#include <inttypes.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+int main(void) {
+ void *buf = buffer_malloc(10, sizeof(int));
+ if (!buf) {
+ fprintf(stderr, "Failed to allocate buffer\n");
+ return 1;
+ }
+
+ printf("capacity: %" PRIu64 "\n", buffer_capacity(buf));
+ printf("size: %" PRIu64 "\n", buffer_count(buf));
+
+ buffer_free(buf);
+ return 0;
+}