(MOD) Refinements and widened extendibilities for Status
This commit is contained in:
0
MemMan/Makefile
Normal file
0
MemMan/Makefile
Normal file
57
MemMan/include/memman.h
Normal file
57
MemMan/include/memman.h
Normal file
@@ -0,0 +1,57 @@
|
||||
#ifndef MEMMAN_H
|
||||
#define MEMMAN_H
|
||||
|
||||
#include <Compound/common.h>
|
||||
#include <Compound/status.h>
|
||||
|
||||
/*
|
||||
Higher the priority it is, the less time for lifespan it has.
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
void *addr;
|
||||
int priority; // -1 for manual
|
||||
} Memory;
|
||||
|
||||
typedef struct {
|
||||
Memory *members;
|
||||
size_t poolsize;
|
||||
int priority;
|
||||
} MemoryPool;
|
||||
|
||||
typedef struct {
|
||||
MemoryPool *members;
|
||||
void *(*allocator)(size_t sz);
|
||||
void (*delocator)(void *addr);
|
||||
} MemoryPoolManager;
|
||||
|
||||
Status memman_memory_allocate(Memory *inst, size_t sz);
|
||||
Status memman_memory_reallocate(Memory *inst, size_t sz);
|
||||
void memman_memory_release(Memory *inst);
|
||||
|
||||
Status memman_memorypool_create(MemoryPool *inst, Memory **members,
|
||||
size_t poolsize);
|
||||
Status memman_memorypool_constr(MemoryPool *inst, Memory **members,
|
||||
size_t poolsize, int priority);
|
||||
Status memman_memorypool_allocate(MemoryPool *inst, int idx, size_t sz);
|
||||
Status memman_memorypool_reallocate(MemoryPool *inst, int idx, size_t sz);
|
||||
Status memman_memorypool_release(MemoryPool *inst, int idx);
|
||||
Status memman_memorypool_prioritise(MemoryPool *inst, int idx);
|
||||
Status memman_memorypool_deprioritise(MemoryPool *inst, int idx);
|
||||
void memman_memorypool_delete(MemoryPool *inst);
|
||||
|
||||
Status memman_memorypoolmanager_create(MemoryPoolManager *inst,
|
||||
MemoryPool **membersptr);
|
||||
Status memman_memorypoolmanager_constr(MemoryPoolManager *inst,
|
||||
MemoryPool **membersptr,
|
||||
void *(*allocator)(size_t sz),
|
||||
void (*delocator)(void *addr));
|
||||
Status memman_memorypoolmanager_addmember(MemoryPoolManager *inst,
|
||||
MemoryPool *newmember);
|
||||
Status memman_memorypoolmanager_removemember(MemoryPoolManager *inst, int idx);
|
||||
Status memman_memorypoolmanager_allocate(MemoryPoolManager *inst,
|
||||
ArrayIndexerRange selected, size_t sz);
|
||||
Status memman_memorypoolmanager_release(MemoryPoolManager *inst,
|
||||
ArrayIndexerRange selected);
|
||||
|
||||
#endif /* MEMMAN_H */
|
35
MemMan/src/memman.c
Normal file
35
MemMan/src/memman.c
Normal file
@@ -0,0 +1,35 @@
|
||||
#include <Compound/common.h>
|
||||
#include <Compound/memman.h>
|
||||
|
||||
/*
|
||||
enum {
|
||||
MEMMAN_RELEASE_LEVEL_INSTANTAL = 0,
|
||||
MEMMAN_RELEASE_LEVEL_STACK = 1,
|
||||
MEMMAN_RELEASE_LEVEL_HEAP = 2
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
void *addr;
|
||||
int release_level;
|
||||
} Memory;
|
||||
|
||||
typedef struct {
|
||||
Memory *members;
|
||||
int release_level;
|
||||
} MemoryPool;
|
||||
|
||||
typedef struct {
|
||||
MemoryPool *members;
|
||||
void *(*allocator)(size_t sz);
|
||||
void (*delocator)(void *addr);
|
||||
} MemoryPoolManager;
|
||||
*/
|
||||
|
||||
int memman_memorypoolmanager_create(MemoryPoolManager *inst,
|
||||
MemoryPool **membersptr)
|
||||
{
|
||||
fails(inst, COMMON_ERROR_INVALID_ARGUMENT);
|
||||
fails(membersptr, COMMON_ERROR_INVALID_ARGUMENT);
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user