Skip to content

ankushT369/smallvec

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

smallvec

smallvec is a hybrid vector written in zig (inspired by SmallVec in Rust) it stores small amount of elements (usually small) in the stack memory to avoid heap allocation. If the threshold for stack elements increase the it fallbacks to heap based allocation.

This is useful for performance-critical code where most needed vectors are small.

Usage

const std = @import("std");
const sv = @import("smallvec");

pub fn main() !void {
    const Vec = sv.SmallVec(u32, 64);
    const N: usize = 1_000;

    // by default it uses std.heap.smp_allocator
    var v = Vec.init(.{});
    defer v.deinit();

    for (0..N) |i| {
        try v.push(@intCast(i));
    }

    while (!v.isEmpty()) {
        if (v.pop()) |value| {
            std.debug.print("{}\n", .{value});
        }
    }
}

About

smallvec is a hybrid vector written in zig (inspired by SmallVec in Rust) it stores small amount of elements (usually small) in the stack memory to avoid heap allocation.

Resources

License

Stars

3 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages