add macros: ptr_array_allocator_xxx

posix_api
YuQing 2022-01-03 10:24:28 +08:00
parent c3f22aa867
commit 7fbdb0cece
1 changed files with 24 additions and 0 deletions

View File

@ -46,6 +46,13 @@ typedef struct
id_name_pair_t elts[0];
} IdNameArray;
typedef struct
{
int alloc;
int count;
void *elts[0];
} PointerArray;
typedef struct array_allocator_context
{
struct fast_allocator_context allocator;
@ -144,6 +151,23 @@ extern "C" {
array_allocator_free(ctx, (VoidArray *)array)
#define ptr_array_allocator_init_ex(ctx, min_bits, max_bits, need_lock) \
array_allocator_init_ex(ctx, "ptr", sizeof(void *), \
min_bits, max_bits, need_lock)
#define ptr_array_allocator_init(ctx, min_bits, max_bits) \
ptr_array_allocator_init_ex(ctx, min_bits, max_bits, true)
#define ptr_array_allocator_alloc(ctx, target_count) \
(PointerArray *)array_allocator_alloc(ctx, target_count)
#define ptr_array_allocator_realloc(ctx, old_array, target_count) \
(PointerArray *)array_allocator_realloc(ctx, \
(VoidArray *)old_array, target_count)
#define ptr_array_allocator_free(ctx, array) \
array_allocator_free(ctx, (VoidArray *)array)
#ifdef __cplusplus
}
#endif