summaryrefslogtreecommitdiff
path: root/src/glibext/umemslice.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/glibext/umemslice.h')
-rw-r--r--src/glibext/umemslice.h80
1 files changed, 80 insertions, 0 deletions
diff --git a/src/glibext/umemslice.h b/src/glibext/umemslice.h
new file mode 100644
index 0000000..54b8433
--- /dev/null
+++ b/src/glibext/umemslice.h
@@ -0,0 +1,80 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * umemslice.h - prototypes pour les allocations en série d'un même type d'objets
+ *
+ * Copyright (C) 2023 Cyrille Bagard
+ *
+ * This file is part of Chrysalide.
+ *
+ * Chrysalide is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Chrysalide is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Chrysalide. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef _GLIBEXT_UMEMSLICE_H
+#define _GLIBEXT_UMEMSLICE_H
+
+
+#include <glib-object.h>
+#include <stdint.h>
+
+
+
+#define G_TYPE_UMEM_SLICE g_umem_slice_get_type()
+#define G_UMEM_SLICE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_UMEM_SLICE, GUMemSlice))
+#define G_IS_UMEM_SLICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_UMEM_SLICE))
+#define G_UMEM_SLICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_UMEM_SLICE, GUMemSliceClass))
+#define G_IS_UMEM_SLICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_UMEM_SLICE))
+#define G_UMEM_SLICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_UMEM_SLICE, GUMemSliceClass))
+
+
+/* Allocateur s'appuyant sur des séries d'objets de même type (instance) */
+typedef struct _GUMemSlice GUMemSlice;
+
+/* Allocateur s'appuyant sur des séries d'objets de même type (classe) */
+typedef struct _GUMemSliceClass GUMemSliceClass;
+
+
+/* Indique le type défini pour un allocateur en série d'objets depuis une même zone mémoire. */
+GType g_umem_slice_get_type(void);
+
+/* Crée un allocateur dédié à la création de zones identiques. */
+GUMemSlice *g_umem_slice_new(size_t);
+
+/* Alloue une nouvelle zone de la taille attendue en mémoire. */
+void *g_umem_slice_alloc(GUMemSlice *);
+
+/* Mémorise un mot de 64 bits dans une nouvelle zone en mémoire. */
+void g_umem_slice_put_uint64(GUMemSlice *, uint64_t);
+
+/* Itérateur pour tranches de mémoire */
+typedef struct _umem_slice_iter_t
+{
+ union
+ {
+ void *data_end; /* Première zone libre */
+ uint64_t *data_end_uint64;
+ unsigned long data_end_ul;
+ };
+ struct _umem_slice_iter_t *next; /* Lien vers tranche suivante */
+
+ void *data[0]; /* Accès au premier élément */
+
+} umem_slice_iter_t;
+
+/* Fournit un itérateur pour les données allouées. */
+const umem_slice_iter_t *g_umem_slice_get_iter(const GUMemSlice *);
+
+
+
+#endif /* _GLIBEXT_UMEMSLICE_H */