Classic opaque type library.
Contains a vector_t
- base ADT for dynamic arrays.
The design allows for development of derived random access containers with ease.
Provides api for array manipulations with extendability in mind.
-
Does not perform auto scaling and tracking of stored elements.
(all these functionalities have to be implemented in derived containers by design) -
Memory alignment is up to user.
Element of the vector are laid out one after another without padding.
You can add byte padding manually in struct of the element type.
Also you are able setdata_offset
to add padding between control struct and contents of the vector.
If you dislike how memory alignment is done, see next point. -
Default allocation strategy is a standard heap allocation, but can be altered.
You can use memalign instead of malloc for instance or custom allocator of your preference.
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
- memswap
-
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/vector.git vector; cd vector; 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 libvector_static.a
or libvector.so
on linux.
If you on Windows platform link to libvector_static.lib
.
#include "vector.h"
int main(void)
{
vector_t *vector = vector_create(.element_size = sizeof(int));
int a = 69;
vector_set(&vector, 0, &a);
vector_set(&vector, 1, TMP_REF(int, 42));
vector_get(vector, 1, &a); // a = 42
vector_destroy(vector);
}