From 0cc9b20c15460213e488bf5e70963b941482f628 Mon Sep 17 00:00:00 2001 From: William Harrington Date: Tue, 14 Jan 2025 16:06:02 -0600 Subject: Add source. --- sdk/other/memory.h | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 sdk/other/memory.h (limited to 'sdk/other/memory.h') 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 +#endif + +#ifndef MEMORY_H_MISSING +#include +#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 + + + -- cgit v1.2.3-54-g00ecf