Vec: A Minimal C Library for Generic Dynamic Arrays with O(1) Amortized Push Operations
By
Lucas_Marchetti
Slow-proofed and worth the wait. Worth its weight in flour.
Summary
Vec is a minimal C library that provides generic, contiguous dynamic arrays with O(1) amortized push operations. It offers a method-style API, geometric growth (doubling capacity), and defensive programming features including overflow guards, bounds-checked accessors, and well-defined behavior for various operations. The library emphasizes cache locality, SIMD-friendliness, and leak safety for C programming.
Key quotes
· 4 pulledVec is a generic, fast, leak‑safe dynamic array for C
It stores elements contiguously, grows geometrically (×2) for amortized O(1) push
The library is defensive by default: overflow guards before allocations, bounds‑checked accessors, and well‑defined behavior
Contiguous memory: better cache locality and prefetching than node‑based structures, fewer pointer indirections, great for iteration and SIMD‑friendly data
You might also wanna read
Cscript Style Guide: A Python-Inspired Approach to C Programming
Cscript is presented as a style guide for writing C code that aims to make C development faster and more Python-like while maintaining C's p
Pigeon's Device: An Independent Loop Optimization Technique in C Programming
The article introduces Pigeon's device, a loop optimization technique in C programming that was independently developed from Duff's device.
Implementing Closures in C Using JIT-Compiled Wrappers for Win32 Window Procedures
The article discusses an advanced programming technique for creating closures in C using JIT-compiled wrappers, specifically applied to Win3
Guidelines for Writing Fully Encapsulated C Programs: Pure vs Performance Approaches
This article presents a comprehensive set of rules and guidelines for writing fully encapsulated C programs, developed by the author over ye
Checked-size Array Parameters in C: Addressing Safety Issues with Array Size Validation
The article discusses a recent attempt to add safety checks for array parameters in the C programming language, specifically within the cryp
Creating a Leak-Free, Thread-Safe Grep Utility in C23 with Safe Programming Practices
The article details the author's experience creating a leak-free, thread-safe grep utility in C23 using a custom header file called safe_c.h
