7#define MAX_ALIGNMENT 2 * 1024 * 1024
8#define ALIGNED(bytes) &(alloc_t){.alignment = bytes}
10#if defined _WIN32 || defined __CYGWIN__
11#define aligned_alloc(alignment, size) _aligned_malloc(size, alignment)
28 .element_size =
sizeof(
int),
30 .size =
sizeof(alloc_t),
31 .data = ALIGNED(MAX_ALIGNMENT),
35 assert((0 == (
size_t)aligned_vector % MAX_ALIGNMENT)
36 &&
"Address must be aligned to MAX_ALIGNMENT");
47 alloc_t* alloc = (alloc_t*)param;
48 return aligned_alloc(alloc->alignment, alloc_size);
54 assert(alloc_size > 0);
57 alloc_t *alloc = (alloc_t*)param;
59 if (alloc_size == alloc->last_size)
64 void *
new = aligned_alloc(alloc->alignment, alloc_size);
67 memcpy(
new, ptr, alloc->last_size);
68 alloc->last_size = alloc_size;
void * vector_realloc(void *const ptr, size_t alloc_size, void *const param)
Reallocates already allocated memory chunk in order to change allocation size.
void * vector_alloc(const size_t alloc_size, void *const param)
Allocates memory chunk of alloc_size.
void vector_free(void *const ptr, void *const param)
Free allocation that was previously allocated.
#define vector_create(...)
Vector constructor.
#define alloc_opts(...)
Use this macro to define allocator opts in vector_opts_t.
void vector_destroy(vector_t *const vector)
Deallocates vector.
Vector control structure type.
Public interface of the vector.