vector
Simple reallocating vector
Summary
| Latest Version | Unknown |
|---|---|
| License | MIT |
| CI Status | Failing |
| Downloads | 0 |
| Last Indexed | 2026-07-21 05:24 |
Tags
Installation
nimble install vector
choosenim install vector
git clone https://github.com/tontinton/vector
OS Compatibility
| Platform | Linux | macOS | Windows | FreeBSD | OpenBSD | NetBSD | Android | iOS | WASM | Embedded |
|---|---|---|---|---|---|---|---|---|---|---|
| vector | ✓ | ✓ | ✓ | - | - | - | - | - | - | - |
Source
| Repository | https://github.com/tontinton/vector |
|---|---|
| Homepage | https://github.com/tontinton/vector |
| Registry Source | nimble_official |
README
Introduction
A simple reallocating vector library for nim.
But wait a second, there is already a seq for holding dynamic arrays, why should I use this stupid vector?
The reasons are:
* --gc=none
* seqs are managed in memory through the gc
* Performance:
* You can allocate the vector with a big size to ensure low allocation count and use it as a simple memory pool
The vector's buffer extends when you add an item using push or extend by a power of 2 when it runs out of memory.
For example:
var vec = initVector[int]() # vec's buffer size is 4 (int.sizeof())
vec.extend(@[1, 2, 3, 4, 5]) # vec's buffer size is 32
# 32 is the lowest power of 2 that is bigger than 20 (5 * int.sizeof())
Notes
The buffer never resizes down (shrinks).
If you really want to shrink your vector, you can allocate a new one using the old one:
var vec = initVector[uint8](1000) # vec's buffer size is 1024
vec.clear() # still 1024
var newVec = initVector(vec) # newVec's buffer size is now float.sizeof()