Remove memcpy use

This commit is contained in:
olemorud
2023-05-15 00:45:52 +02:00
committed by Ole Morud
parent 5e92c4eaea
commit cd68347dd9
2 changed files with 10 additions and 12 deletions

View File

@@ -1,14 +1,13 @@
#include "arena.h"
#include "alloc_backend.h"
#include <errno.h>
#include <unistd.h>
#include <string.h>
#define ARENA_SIZE ((size_t)(128*sysconf(_SC_PAGE_SIZE)))
/*
* Allocates and returns new arena
*/
@@ -21,15 +20,15 @@ struct arena* arena_new()
if (p == NULL)
return NULL;
struct arena a = {
arena_t *a = (arena_t*)p;
*a = (arena_t){
.begin = p + sizeof(struct arena),
.next = p + sizeof(struct arena),
.cap = size
};
memcpy(p, &a, sizeof a);
return (struct arena*)p;
return (arena_t*)a;
}

View File

@@ -2,18 +2,17 @@
#ifndef ARENA_H
#define ARENA_H
#include <stddef.h> // ptrdiff_t
struct arena {
typedef struct arena {
unsigned char *begin,
*next;
ptrdiff_t cap;
};
} arena_t;
struct arena* arena_new();
void arena_reset(struct arena *a);
void* arena_alloc(struct arena *a, size_t len);
arena_t* arena_new();
void arena_reset(arena_t *a);
void* arena_alloc(arena_t *a, size_t len);
#endif