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.
Implementation details
- 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 set data_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.
See Full Documentation
Supported platforms
Platforms | CI/CD | COVERAGE |
Linux | | |
Windows | | |
Memory layout
Dependencies
Build System
- 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
Libraries
- stdlib
- string
- stdbool
- sys/types
- memswap
Build Process
- 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
- On Windows:
- Install msys2 environment.
- In msys2 shell run:
pacman -S curl git mingw-w64-ucrt-x86_64-gcc \
mingw-264-ucrt-x86_64-check \
autotools autoconf-archive lcov
Set up git newline \n
to \r\n
convertion (windows style): git config --global core.autocrlf input
- 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<threads> option for multithreaded building)
- 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:
Usage
Link against libvector_static.a
or libvector.so
on linux.
If you on Windows platform link to libvector_static.lib
.
Minimal Example
int main(void)
{
int a = 69;
}
void * vector_get(const vector_t *const vector, const size_t index)
Returns pointer for the element at index.
void vector_set(vector_t *const vector, const size_t index, const void *const value)
Sets element at given index to a value.
#define vector_create(...)
Vector constructor.
void vector_destroy(vector_t *const vector)
Deallocates vector.
Vector control structure type.
Public interface of the vector.
#define TMP_REF(type, value)
Create temporary typed reference.