Vec: A Generic Vector for C Overview Vec is a minimal, generic, fast, and leak-safe dynamic array library for C. It offers contiguous memory storage with amortized O(1) push operations and provides a natural method-style API, especially attractive for those who prefer object syntax in C. Key features: Contiguous storage for better cache locality and SIMD-friendly data. Geometric doubling growth of capacity to ensure amortized constant-time pushes. Truly generic by using elemsize for type erasure without macros or void arithmetic in client code. Defensive design with overflow guards, bounds-checked accessors, and safe handling of empty/shrink/destroy operations. Provides both free-function and method-style APIs (method-style requires non-LITE build). Design and Memory Model Elements are stored contiguously in a single growable buffer. Capacity doubles upon reaching limits for amortized O(1) push operations. len tracks current element count, while capacity indicates allocated slots. vecreserve pre-allocates capacity; vecshrink frees excess capacity and handles zero-length buffers safely. Iteration uses standard pointer arithmetic over element types: Bulk operations utilize efficient memcpy and memmove. Usage & API Build and Installation Linking Example Compile-time Option LITE mode: no method pointers; exposes only free-function API. Build with: Core API (Free-function style) vecpush: Append a copy of element; returns pointer to new element or NULL on failure. vecpop: Remove last element; no-op when empty. vecremove: Remove element at index i with tail shift; returns success status. vecat: Access element at index; NULL if out-of-bounds. vecback: Access last element; NULL if empty. vecreserve: Ensure minimum capacity. vecshrink: Reduce capacity to current length. vecclear: Set length to zero without freeing capacity. vecdestroy: Free memory and reset vector state. Method-style API Available when built without -DLITE, accessed as function pointers in Vec struct: Example: Free-function style Example: Method-style Safety and Semantics Checks for sizet overflow during capacity calculations. Returning NULL or 0 on allocation failures, setting `errno =