Always zero memory from arena

This commit is contained in:
Kovid Goyal 2024-12-17 07:37:34 +05:30
parent dc1bed1bd1
commit 72d88e75aa
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
3 changed files with 4 additions and 7 deletions

View file

@ -51,11 +51,9 @@ MA_CAT(MA_NAME, _get)(MA_TYPE_NAME *self, size_t sz) {
void *chunk = NULL;
if (MA_BLOCK_SIZE >= sizeof(void*) && MA_BLOCK_SIZE % sizeof(void*) == 0) {
if (posix_memalign(&chunk, MA_BLOCK_SIZE, block_sz) != 0) chunk = NULL;
} else chunk = malloc(block_sz);
memset(chunk, 0, block_sz);
} else chunk = calloc(1, block_sz);
if (!chunk) { return NULL; }
#ifdef MA_ZERO_MEMORY
memset(chunk, 0, block_sz);
#endif
if (count > self->capacity) {
size_t capacity = MAX(8u, 2 * self->capacity);
MA_BLOCK_TYPE_NAME *blocks = realloc(self->blocks, capacity * sizeof(MA_BLOCK_TYPE_NAME));
@ -75,6 +73,5 @@ MA_CAT(MA_NAME, _get)(MA_TYPE_NAME *self, size_t sz) {
#undef MA_ARENA_NUM_BLOCKS
#undef MA_TYPE_NAME
#undef MA_BLOCK_TYPE_NAME
#undef MA_ZERO_MEMORY
#undef MA_CAT
#undef MA_CAT_

View file

@ -28,7 +28,6 @@ static_assert(MA_BLOCK_SIZE > sizeof(SpritePosKey) + 2, "increase arena block si
#define MA_NAME Val
#define MA_BLOCK_SIZE sizeof(VAL_TY)
#define MA_ARENA_NUM_BLOCKS (2048u / MA_BLOCK_SIZE)
#define MA_ZERO_MEMORY
#include "arena.h"

View file

@ -7,9 +7,10 @@
#include "data-types.h"
typedef struct Chars {
size_t count;
const char_type *chars;
size_t count;
} Chars;
static_assert(sizeof(Chars) == sizeof(void*) + sizeof(size_t), "reorder Chars");
#define NAME chars_map
#define KEY_TY Chars