Generic dynamic array for C.
Is an extension over vector.
Keeps containing data sequential, tracks amount of stored elements
and grows/shrinks on demand.
Resize functionality is parametrized for flexability.
Has variety of common array operation, like append, insert, search, etc ...
Vector API can seamlessly operate on dynarr_t *
.
Supports further extension.
Platforms | CI/CD | COVERAGE |
---|---|---|
Linux | ||
Windows |
- gcc
- make
- autotools:
automake >= 1.11.2
autoconf
autoconf-archive - install separately (for valgrind support)
libtool - check - testing framework
- valgrind - for memory leak checks
- lcov - for code coverage analizing
- stdlib
- string
- stdbool
- sys/types
- math
-
Install Build System dependencies:
- On Debian / Ubuntu:
- In your fav shell run:
sudo apt-get install gcc make automake autoconf autoconf-archive libtool \ check valgrind lcov
- In your fav shell run:
- On Windows:
- Install msys2 environment.
- In msys2 shell run:
Set up git newline
pacman -S curl git mingw-w64-ucrt-x86_64-gcc \ mingw-264-ucrt-x86_64-check \ autotools autoconf-archive lcov
\n
to\r\n
convertion (windows style):git config --global core.autocrlf input
- On Debian / Ubuntu:
-
Clone the repository:
git clone https://github.com/evjeesm/dynarr.git dynarr; cd dynarr; git submodule update --init --recursive;
-
Configure project:
./autogen.sh && ./configure CFLAGS=<YOUR COMPILATION FLAGS> --prefix=</path/to/install/folder/>
-
Build project: (use -j option for multithreaded building)
make
-
Run Tests:
make check make check-valgrind # optional memory check
-
If no errors occured during check you can safely install library
in your desired prefix path that you specified at configure step.
Procede to installation:make install
Link against libdynarr_static.a
or libdynarr.so
on linux.
If you on Windows platform link to libdynarr_static.lib
.
Requires standard math library, so remember to provide -lm
.
Requires linking with vector's libraries.
#include "dynarr.h"
int main(void)
{
dynarr_t *dynarr = dynarr_create(.element_size = sizeof(int));
int a = 69;
dynarr_append(&dynarr, &a);
dynarr_append(&dynarr, TMP_REF(int, 42));
dynarr_last(dynarr, &a); // a = 42
dynarr_destroy(dynarr);
}