Put the custom allocator in its own lib, as to lessen the difficulty to switch between libc's allocator and a custom one (#7)
This commit is contained in:
parent
713f0f0302
commit
cb7f3c3fdf
85 changed files with 1121 additions and 877 deletions
|
|
@ -43,7 +43,7 @@ t_hashmap_C__PREFIX__ *new_hashmap_with_buckets_C__PREFIX__(
|
|||
hmap->cfunc = cfunc;
|
||||
hmap->drop = drop;
|
||||
if (hmap->buckets == NULL)
|
||||
return ((void)me_free(hmap), NULL);
|
||||
return ((void)mem_free(hmap), NULL);
|
||||
return (hmap);
|
||||
}
|
||||
|
||||
|
|
@ -57,13 +57,13 @@ void drop_hashmap_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap)
|
|||
if (hmap->buckets[index])
|
||||
{
|
||||
hmap->drop(hmap->buckets[index]->kv);
|
||||
me_free(hmap->buckets[index]);
|
||||
mem_free(hmap->buckets[index]);
|
||||
}
|
||||
index++;
|
||||
}
|
||||
hasher_finish(&hmap->hasher);
|
||||
me_free(hmap->buckets);
|
||||
me_free(hmap);
|
||||
mem_free(hmap->buckets);
|
||||
mem_free(hmap);
|
||||
}
|
||||
|
||||
t_entry_C__PREFIX__ *hashmap_get_entry_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap,
|
||||
|
|
|
|||
|
|
@ -51,6 +51,6 @@ void remove_hashmap_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap, C__KEYTYPE__ *key)
|
|||
else
|
||||
prev->next = entry->next;
|
||||
hmap->drop(entry->kv);
|
||||
me_free(entry);
|
||||
mem_free(entry);
|
||||
hmap->buckets[hashed_key % hmap->num_buckets] = NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
#include "me/mem/mem_copy.h"
|
||||
#include "me/mem/mem_set_zero.h"
|
||||
#include "me/types.h"
|
||||
#include "me/alloc/alloc.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/vec/vec_C__PREFIX__.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
|
|
@ -43,7 +43,7 @@ t_error vec_C__PREFIX___push(t_vec_C__PREFIX__ *vec, C__TYPENAME__ element)
|
|||
new_capacity = (vec->capacity * 3) / 2 + 1;
|
||||
while (vec->len + 1 > new_capacity)
|
||||
new_capacity = (new_capacity * 3) / 2 + 1;
|
||||
vec->buffer = me_realloc_array(vec->buffer, new_capacity, sizeof(C__TYPENAME__));
|
||||
vec->buffer = mem_realloc_array(vec->buffer, new_capacity, sizeof(C__TYPENAME__));
|
||||
vec->capacity = new_capacity;
|
||||
}
|
||||
vec->buffer[vec->len] = element;
|
||||
|
|
@ -63,7 +63,7 @@ t_error vec_C__PREFIX___reserve(t_vec_C__PREFIX__ *vec, t_usize wanted_capacity)
|
|||
new_capacity = (vec->capacity * 3) / 2 + 1;
|
||||
while (wanted_capacity > new_capacity)
|
||||
new_capacity = (new_capacity * 3) / 2 + 1;
|
||||
vec->buffer = me_realloc_array(vec->buffer, new_capacity, sizeof(C__TYPENAME__));
|
||||
vec->buffer = mem_realloc_array(vec->buffer, new_capacity, sizeof(C__TYPENAME__));
|
||||
vec->capacity = new_capacity;
|
||||
}
|
||||
return (NO_ERROR);
|
||||
|
|
@ -100,5 +100,5 @@ void vec_C__PREFIX___free(t_vec_C__PREFIX__ vec)
|
|||
vec.len--;
|
||||
}
|
||||
}
|
||||
me_free(vec.buffer);
|
||||
mem_free(vec.buffer);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue