A modern, user friendly, generic, type-safe and fast C99 container library: String, Vector, Sorted and Unordered Map and Set, Deque, Forward List, Smart Pointers, Bitset and Random numbers.
MIT License
1.34k
stars
73
forks
source link
Trying to use vector with custom memory allocator #70
I am trying to use a vector with a custom memory allocator and
I followed the example Per container-instance customization.
I am probably doing something wrong because the compiler complains (see below).
Is there something missing in the allocator definition ?
Regards.
stc/include/stc/cvec.h:311:36: error: too many arguments provided to function-like macro invocation
_cx_value* d = (_cx_value*)i_realloc(self->data, cap*c_sizeof(i_key));
^
stc/include/stc/priv/template.h:51:21: note: expanded from macro 'i_realloc'
#define i_realloc c_JOIN(i_allocator, _realloc)
^
stc/include/stc/ccommon.h:50:22: note: expanded from macro 'c_JOIN'
#define c_JOIN(a, b) c_JOIN0(a, b)
^
stc/include/stc/ccommon.h:49:23: note: expanded from macro 'c_JOIN0'
#define c_JOIN0(a, b) a ## b
^
<scratch space>:32:1: note: expanded from here
alloc_realloc
^
./my_alloc.h:12:53: note: expanded from macro 'alloc_realloc'
#define alloc_realloc(p, sz) my_realloc(c_extend(self)->ctx, p, sz)
^
stc/include/stc/extend.h:59:9: note: macro 'c_extend' defined here
#define c_extend() c_container_of(self, _cx_MEMB(_ext), get)
^
In file included from main.c:13:
In file included from ./my_alloc.h:18:
In file included from stc/include/stc/extend.h:66:
stc/include/stc/cvec.h:311:36: error: use of undeclared identifier 'c_extend'
_cx_value* d = (_cx_value*)i_realloc(self->data, cap*c_sizeof(i_key)
Hi. Yes there is a bug in the docs, will fix it (point 1.).
c_extend() does not take any arguments (self is used internally).
You forgot to init v1 to {0};
STC uses purely signed integers for sizes and indices, i.e. also for the allocator functions - consider to change from size_t to intptr_t (or ptrdiff_t if you prefer) to avoid warning with -Wconversion, and cast to size_t in the calls to std alloc functions.
Hi,
I am trying to use a vector with a custom memory allocator and I followed the example Per container-instance customization. I am probably doing something wrong because the compiler complains (see below). Is there something missing in the allocator definition ? Regards.
Errors from: clang -I stc/include -fsanitize=address,leak main.c my_alloc.c -o vec
my_alloc.c
my_alloc.h
main.c