renamed context to context
This commit is contained in:
parent
fba1b6487f
commit
267ec89571
@ -6,8 +6,8 @@
|
|||||||
#include "magic_memory.h"
|
#include "magic_memory.h"
|
||||||
|
|
||||||
|
|
||||||
magic_memory_t *magic_memory_begin(void) {
|
magic_memory_context_t *magic_memory_begin(void) {
|
||||||
magic_memory_t *new_mm = (magic_memory_t *) malloc(sizeof(magic_memory_t));
|
magic_memory_context_t *new_mm = (magic_memory_context_t *) malloc(sizeof(magic_memory_context_t));
|
||||||
|
|
||||||
if (new_mm == NULL) {
|
if (new_mm == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -19,9 +19,9 @@ magic_memory_t *magic_memory_begin(void) {
|
|||||||
return new_mm;
|
return new_mm;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *magic_malloc(magic_memory_t *magic_memory, size_t size) {
|
void *magic_malloc(magic_memory_context_t *magic_memory, size_t size) {
|
||||||
|
|
||||||
magic_memory_t *mm = (magic_memory_t *) malloc(sizeof(magic_memory_t));
|
magic_memory_context_t *mm = (magic_memory_context_t *) malloc(sizeof(magic_memory_context_t));
|
||||||
|
|
||||||
if (mm == NULL) {
|
if (mm == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -37,7 +37,7 @@ void *magic_malloc(magic_memory_t *magic_memory, size_t size) {
|
|||||||
mm->ptr = new_ptr;
|
mm->ptr = new_ptr;
|
||||||
mm->next = NULL;
|
mm->next = NULL;
|
||||||
|
|
||||||
magic_memory_t *p = magic_memory;
|
magic_memory_context_t *p = magic_memory;
|
||||||
while (p->next != NULL) {
|
while (p->next != NULL) {
|
||||||
p = p->next;
|
p = p->next;
|
||||||
}
|
}
|
||||||
@ -46,9 +46,9 @@ void *magic_malloc(magic_memory_t *magic_memory, size_t size) {
|
|||||||
return new_ptr;
|
return new_ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void magic_free(magic_memory_t *magic_memory, void *ptr) {
|
void magic_free(magic_memory_context_t *magic_memory, void *ptr) {
|
||||||
|
|
||||||
magic_memory_t *p = magic_memory;
|
magic_memory_context_t *p = magic_memory;
|
||||||
while (p != NULL) {
|
while (p != NULL) {
|
||||||
if (p->ptr == ptr) {
|
if (p->ptr == ptr) {
|
||||||
free(p->ptr);
|
free(p->ptr);
|
||||||
@ -60,15 +60,15 @@ void magic_free(magic_memory_t *magic_memory, void *ptr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void magic_cleanup(magic_memory_t *magic_memory) {
|
void magic_cleanup(magic_memory_context_t *magic_memory) {
|
||||||
|
|
||||||
magic_memory_t *p = magic_memory;
|
magic_memory_context_t *p = magic_memory;
|
||||||
while (p != NULL) {
|
while (p != NULL) {
|
||||||
|
|
||||||
if (p->ptr != NULL) {
|
if (p->ptr != NULL) {
|
||||||
free(p->ptr); // Free up the block this chain element points to
|
free(p->ptr); // Free up the block this chain element points to
|
||||||
}
|
}
|
||||||
magic_memory_t* p_old = p;
|
magic_memory_context_t* p_old = p;
|
||||||
p = p->next;
|
p = p->next;
|
||||||
free(p_old); // Free up the chain piece itself
|
free(p_old); // Free up the chain piece itself
|
||||||
}
|
}
|
||||||
|
@ -5,14 +5,15 @@
|
|||||||
#ifndef CAFF_PREVIEWER_MAGIC_MEMORY_H
|
#ifndef CAFF_PREVIEWER_MAGIC_MEMORY_H
|
||||||
#define CAFF_PREVIEWER_MAGIC_MEMORY_H
|
#define CAFF_PREVIEWER_MAGIC_MEMORY_H
|
||||||
|
|
||||||
typedef struct magic_memory_t {
|
typedef struct magic_memory_context_t {
|
||||||
void* next;
|
void* next;
|
||||||
void *ptr;
|
void *ptr;
|
||||||
} magic_memory_t;
|
} magic_memory_context_t;
|
||||||
|
|
||||||
magic_memory_t* magic_memory_begin(void);
|
magic_memory_context_t* magic_memory_begin(void);
|
||||||
void* magic_malloc(magic_memory_t* magic_memory, size_t size);
|
void* magic_malloc(magic_memory_context_t* magic_memory, size_t size);
|
||||||
void magic_free(magic_memory_t* magic_memory, void* ptr);
|
|
||||||
void magic_cleanup(magic_memory_t* magic_memory);
|
void magic_free(magic_memory_context_t* magic_memory, void* ptr);
|
||||||
|
void magic_cleanup(magic_memory_context_t* magic_memory);
|
||||||
|
|
||||||
#endif //CAFF_PREVIEWER_MAGIC_MEMORY_H
|
#endif //CAFF_PREVIEWER_MAGIC_MEMORY_H
|
||||||
|
Loading…
Reference in New Issue
Block a user