LS Vector
Minimal, single-header dynamic array (vector) for C.
- Type-safe via macro code generation (not macro function calls)
- ANSI C
- Header-only
- Dynamic resizing
- Configurable memory allocators
Quick Start
-
Copy
ls_vec.hto your project. -
Define any number of vector types:
LS_VEC_INLINE(int, int_vector)OR for separate declaration/implementation:
// In header: LS_VEC_DECL(int, int_vector) // In source file: LS_VEC_IMPL(int, int_vector) -
Use the vector with normal C function calls:
int_vector vec; int_vector_init(&vec); if (!int_vector_push(&vec, 42)) { // push failed, allocation failure, handle that here } // Access elements via vec.data[i] // Check size via vec.size int_vector_free(&vec);
See ls_vec.h for detailed documentation and usage patterns.
Custom Memory Allocators
Configure custom allocators by defining these macros before including the header:
#define LS_REALLOC my_realloc
#define LS_FREE my_free
#include "ls_vec.h"
The allocators must behave exactly like standard realloc and free.
See ls_vec.h for detailed documentation and usage patterns.
License
MIT.
