All Projects → rbnx → rvec

rbnx / rvec

Licence: other
RAII dynamic array in C

Programming Languages

c
50402 projects - #5 most used programming language

Labels

Projects that are alternatives of or similar to rvec

SACK
System Abstraction Component Kit
Stars: ✭ 18 (+0%)
Mutual labels:  generic
simple json
Simple way to dynamically convert from and to JSON using build-time generators given a type.
Stars: ✭ 15 (-16.67%)
Mutual labels:  generic
anchor
Create Dynamic CLI's as your GitOps Marketplace
Stars: ✭ 38 (+111.11%)
Mutual labels:  generic
generic
flexible data type for Go
Stars: ✭ 43 (+138.89%)
Mutual labels:  generic
generic
Generic programming library for Python
Stars: ✭ 50 (+177.78%)
Mutual labels:  generic
io-api
📐 API design example by I/O, the demo implementation of https://dzone.com/articles/generic-inputoutput-api-java
Stars: ✭ 46 (+155.56%)
Mutual labels:  generic
generic
generic streamlink plugin
Stars: ✭ 18 (+0%)
Mutual labels:  generic
GenericRecyclerAdapter
Easiest way to use RecyclerView. Reduce boilerplate code! You don't need to write adapters for listing pages anymore!
Stars: ✭ 53 (+194.44%)
Mutual labels:  generic
UseCases
This a library that offers a generic implementation of the data layers from the clean architecture by Uncle bob.
Stars: ✭ 23 (+27.78%)
Mutual labels:  generic
atomig
Generic and convenient `std` atomics via `Atomic<T>`
Stars: ✭ 32 (+77.78%)
Mutual labels:  generic
Astview
Astview is a graphical viewer for abstract syntax trees
Stars: ✭ 20 (+11.11%)
Mutual labels:  generic
Johnny
Melodic Caching for Swift
Stars: ✭ 36 (+100%)
Mutual labels:  generic
Swiftish
A fully generic Swift vector & matrix library
Stars: ✭ 17 (-5.56%)
Mutual labels:  generic
QuickDB
A Generic CoreData Manager to accept any type of objects. Fastest way for adding a Database to your project.
Stars: ✭ 16 (-11.11%)
Mutual labels:  generic
go2linq
Generic Go implementation of .NET's LINQ to Objects.
Stars: ✭ 41 (+127.78%)
Mutual labels:  generic
Genumerics
Genumerics is a high-performance .NET library for generic numeric operations
Stars: ✭ 16 (-11.11%)
Mutual labels:  generic
ertis-auth
Generic token generator and validator service like auth
Stars: ✭ 28 (+55.56%)
Mutual labels:  generic
mgs
C++14 codec library
Stars: ✭ 24 (+33.33%)
Mutual labels:  generic
servicestack-client
ServiceStack Service Client, Server Events and validation library
Stars: ✭ 17 (-5.56%)
Mutual labels:  generic
GenericAdapter
⛳️ Easy to use android databinding ready recyclerview adapter
Stars: ✭ 26 (+44.44%)
Mutual labels:  generic

rvec

RAII dynamic array in C

About

rvec is a lightweight and generic dynamic array library that makes use of GCC/Clang's cleanup extension to release the memory being used by the array once it goes out of scope.

Usage

rvec_t(type) v;
rvec_init(v);
rvec_push(v,val);
#include <stdio.h>
#include "rvec.h"


int main(int argc, const char *argv[]) {
    rvec_t(int) v1;
    rvec_init(v1);

    printf("cap: %zu, size: %zu\n", rvec_capacity(v1), rvec_size(v1));

    for(size_t i = 0; i < 1000; i++) {
      rvec_push(v1,i);
    }

    printf("last item: %d\n",rvec_pop(v1));

    printf("1st item: %d\n",rvec_get(v1,0));
    // or 
    printf("1st item: %d\n",rvec_i(v1,0));

    rvec_set(v1,0,999);
    // or
    rvec_i(v1,0) = 999;

    rvec_resize(v1,100);

    {
      rvec_t(double *) v2;
      rvec_init(v2);
    } // <--- v2 freed here

    return 0;
} // <-- v1 freed here

API

rvec_init(v)

Initialises the array, it must be called before any other function.

rvec_size(v)

Evaluates to the size of the array.

rvec_capacity(v)

Evaluates to the capacity of the array.

rvec_push(v,x)

Adds a new element at the end of the array.

rvec_pop(v)

Pops and returns the last value.

rvec_i(v,i)

Expands to (v)->data[(i)], it can be used like this: rvec_i(v,0) = value; or x = rvec_i(v,0);.

rvec_set(v,i,x)

rvec_set(v,index,value);.

rvec_get(v,i)

rvec_get(v,index);.

rvec_begin(v)

Returns a pointer to the first element of the array.

rvec_end(v)

Returns a pointer to one-past-the-end of the array, (like std::vector::end).

rvec_resize(v,sz)

Resizes the array.

rvec_copy(dest,src)

Copies the elements of src into dest. dest will be resized as needed.

rvec_destroy

Destroys the array. Only useful if you are using the library without RAII support (see #RVEC_NO_RAII in rvec.h).

License

https://github.com/rbnx/rvec/blob/master/rvec.h#L1-L5

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].