This commit is contained in:
cfif 2025-06-02 13:26:40 +03:00
commit 6a4caf24ca
3 changed files with 85 additions and 0 deletions

40
SimpleIndelibleMalloc.c Normal file
View File

@ -0,0 +1,40 @@
//
// Created by zemon on 14.07.2022.
//
#include <memory.h>
#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,
};
}

28
SimpleIndelibleMalloc.h Normal file
View File

@ -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

17
modular.json Normal file
View File

@ -0,0 +1,17 @@
{
"dep": [
{
"type": "git",
"provider": "Smart_Components_Aurus",
"repo": "MemoryAllocationInterface"
}
],
"cmake": {
"inc_dirs": [
"./"
],
"srcs": [
"./**.c"
]
}
}