aboutsummaryrefslogtreecommitdiff
path: root/include/cu/res.h
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2023-04-01 10:53:44 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2023-04-01 10:53:44 +0300
commitad18c24e7223b1c0d48a20ba9b618c4eaf1e3a84 (patch)
tree86f3cba0b5b4bf4b7e49b96ceb61bec8b0be2780 /include/cu/res.h
parentb8211cda90f8a9cb14657d3328cfa9ec78722c5c (diff)
downloadek-ad18c24e7223b1c0d48a20ba9b618c4eaf1e3a84.tar.gz
ek-ad18c24e7223b1c0d48a20ba9b618c4eaf1e3a84.zip
fix gitignore
Diffstat (limited to 'include/cu/res.h')
-rw-r--r--include/cu/res.h57
1 files changed, 57 insertions, 0 deletions
diff --git a/include/cu/res.h b/include/cu/res.h
new file mode 100644
index 0000000..e1a1fc3
--- /dev/null
+++ b/include/cu/res.h
@@ -0,0 +1,57 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later */
+
+/**
+ * @file res.h
+ * Simple resource manager header.
+ */
+
+#ifndef CT_RES_H
+#define CT_RES_H
+
+#include <stddef.h>
+
+/**
+ * Very simple resource manager.
+ * Keeps track of all allocations and frees them all at once.
+ */
+struct res {
+ /** Number of allocations. */
+ size_t n;
+ /** Maximum number of allocations. */
+ size_t max;
+ /** Pointer to array of pointers to allocations. */
+ void **p;
+};
+
+/**
+ * Create new resource manager.
+ *
+ * @return Pointer to resource manager.
+ */
+struct res *res_create();
+
+/**
+ * Resource manager wrapper around malloc().
+ *
+ * @param r Resource manager.
+ * @param size Size of allocation.
+ * @return Pointer to newly allocated area.
+ */
+void *res_alloc(struct res *r, size_t size);
+
+/**
+ * Add already alloced pointer to manager.
+ *
+ * @param r Resource manager.
+ * @param p Pointer to manage.
+ */
+void res_add(struct res *r, void *p);
+
+/**
+ * Destroy resource manager and free all associated allocations.
+ *
+ * @param r Resource manager to destroy.
+ */
+void res_destroy(struct res *r);
+
+#endif /* CT_RES_H */