commit 6a4caf24ca9d161abfd2025f6b061b290f8e7935 Author: cfif Date: Mon Jun 2 13:26:40 2025 +0300 Init diff --git a/SimpleIndelibleMalloc.c b/SimpleIndelibleMalloc.c new file mode 100644 index 0000000..a477db3 --- /dev/null +++ b/SimpleIndelibleMalloc.c @@ -0,0 +1,40 @@ +// +// Created by zemon on 14.07.2022. +// + +#include +#include "SimpleIndelibleMalloc.h" + +void SimpleIndelibleMalloc_Init(tSimpleIndelibleMalloc *env, uint8_t *buffer, size_t size) { + env->buffer = buffer; + env->size = size; + env->used = 0; +} + +void SimpleIndelibleMalloc_Clear(tSimpleIndelibleMalloc *env) { + memset(env->buffer, 0, env->size); +} + +static void *SimpleIndelibleMalloc_Get(tSimpleIndelibleMalloc *env, size_t len) { + if ((env->used + len) > env->size) { + return 0; + } + + void *result = env->buffer + env->used; + env->used += len; + return result; +} + + +static void SimpleIndelibleMalloc_Free(tSimpleIndelibleMalloc *env, void *ptr) { + //do nothing, it's indelible +} + +tMemAllocInterface SimpleIndelibleMalloc_GetInterface(tSimpleIndelibleMalloc *env) { + return (tMemAllocInterface) { + .env = env, + .free = (void *) SimpleIndelibleMalloc_Free, + .alloc = (void *) SimpleIndelibleMalloc_Get, + }; +} + diff --git a/SimpleIndelibleMalloc.h b/SimpleIndelibleMalloc.h new file mode 100644 index 0000000..3186ac6 --- /dev/null +++ b/SimpleIndelibleMalloc.h @@ -0,0 +1,28 @@ +// +// Created by zemon on 14.07.2022. +// + +#ifndef PDM_FIR_TEST_simple_indelible_MALOCK_H +#define PDM_FIR_TEST_simple_indelible_MALOCK_H + +#include "stdlib.h" +#include "stdbool.h" +#include "stdint.h" +#include "MemoryAllocationInterface.h" + + +typedef struct { + uint8_t *buffer; + size_t size; + size_t used; +} tSimpleIndelibleMalloc; + + +void SimpleIndelibleMalloc_Init(tSimpleIndelibleMalloc *env, uint8_t *buffer, size_t size); + +void SimpleIndelibleMalloc_Clear(tSimpleIndelibleMalloc *env); + +tMemAllocInterface SimpleIndelibleMalloc_GetInterface(tSimpleIndelibleMalloc *env); + + +#endif //PDM_FIR_TEST_simple_indelible_MALOCK_H diff --git a/modular.json b/modular.json new file mode 100644 index 0000000..815120d --- /dev/null +++ b/modular.json @@ -0,0 +1,17 @@ +{ + "dep": [ + { + "type": "git", + "provider": "Smart_Components_Aurus", + "repo": "MemoryAllocationInterface" + } + ], + "cmake": { + "inc_dirs": [ + "./" + ], + "srcs": [ + "./**.c" + ] + } +} \ No newline at end of file