aboutsummaryrefslogtreecommitdiffstats
path: root/sdk/other/memory.h
diff options
context:
space:
mode:
authorWilliam Harrington <kb0iic@berzerkula.org>2025-01-14 16:06:02 -0600
committerWilliam Harrington <kb0iic@berzerkula.org>2025-01-14 16:06:02 -0600
commit0cc9b20c15460213e488bf5e70963b941482f628 (patch)
treebb0143245583ec846630f39bfa2258dba640ccd7 /sdk/other/memory.h
parent0e084ade5069756d487b5c948c48b777e37c00c9 (diff)
Add source.
Diffstat (limited to 'sdk/other/memory.h')
-rw-r--r--sdk/other/memory.h103
1 files changed, 103 insertions, 0 deletions
diff --git a/sdk/other/memory.h b/sdk/other/memory.h
new file mode 100644
index 0000000..902edd2
--- /dev/null
+++ b/sdk/other/memory.h
@@ -0,0 +1,103 @@
+/*
+ * Portable memory manipulation and management routines.
+ * $Id$
+ * Copyright (c) 1997 by Tycho Softworks.
+ * For conditions of distribution and reuse see product license.
+ */
+
+#ifndef __OTHER_MEMORY_H__
+#define __OTHER_MEMORY_H__
+
+#ifndef __STD_TYPES_H__
+#include <std/types.h>
+#endif
+
+#ifndef MEMORY_H_MISSING
+#include <memory.h>
+#endif
+
+#ifndef __MEMALIGN
+#define __MEMALIGN sizeof(ptr_t)
+#endif
+
+#ifndef __OBJALIGN
+#define __OBJALIGN __MEMALIGN
+#endif
+
+struct _mempool;
+struct _mempage;
+struct _memfree;
+struct _memcell;
+
+typedef struct _mempool
+{
+ int mem_psize;
+ int mem_pcount;
+ int mem_pused;
+ void *(*mem_pfault)(struct _mempool *mem, int reqsize);
+ struct _memfree *mem_free;
+ struct _mempage *mem_reuse;
+ struct _mempage *mem_last;
+} MEMPOOL;
+
+typedef struct _mempage
+{
+ struct _mempage *page_next;
+ int page_used;
+ uchar page[ EMPTY ];
+} MEMPAGE;
+
+typedef struct _memfree
+{
+ struct _memfree *next;
+ struct _memcell *list;
+ int size;
+} _MEMFREE;
+
+typedef struct _memcell
+{
+ void *next;
+} _MEMCELL;
+
+#define memfault(mem, fault) mem->mem_pfault = fault;
+#define memfirst(mem) ((MEMPAGE *)((char *)(mem) - sizeof(MEMPAGE)))
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef __NAMESPACE
+#define mempool __NAMESPACE(mempool)
+#define memreuse __NAMESPACE(memreuse)
+#define memrelease __NAMESPACE(memrelease)
+#define memreq __NAMESPACE(memreq)
+#define memlreq __NAMESPACE(memlreq)
+#define strreq __NAMESPACE(strreq)
+#define strlreq __NAMESPACE(strlreq)
+#define memdup __NAMESPACE(memdup)
+#define memalloc __NAMESPACE(memalloc)
+#define memfree __NAMESPACE(memfree)
+#endif
+
+MEMPOOL *mempool(int psize, int pcount);
+void memreuse(MEMPOOL *mem);
+void memrelease(MEMPOOL *mem);
+void *memreq(MEMPOOL *mem, size_t memsize);
+void *memlreq(MEMPOOL *mem, size_t memsize);
+char *strreq(MEMPOOL *mem, const char *str);
+char *strlreq(MEMPOOL *mem, const char *str);
+void *memdup(void *, size_t);
+
+/* more advanced allocation schemes */
+
+void *memalloc(MEMPOOL *mem, int memsize);
+void memfree(MEMPOOL *mem, void *obj, int memsize);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+
+