[mainpage] [tags]

module: vector

A 100% typesafe generic vector for C.

This module contains macros, types and functions for MX_VECTOR whic is a a 100% typesafe generic vector object for C. The underlying type must be bit-copy-correct which means that a binary copy retains proper functioning and takes over ownership of any internal buffers.

The interface of MX_VECTOR is done through macros and generic type-indenpendent functions perform the vector operations. In contrast to C++ vector types, the code size when using MX_VECTOR is constant regardless of how many vector types are instantiated.

The correct operation of MX_VECTOR depends on some things that not in the C standard:

All of the compilers I have tested give no warnings on the MX_VECTOR code and seem to function properly. I have tested 16 and 32 bit compilers as well as compilers with various byte orders.

MX_VECTOR objects themselves are bit-copy-correct which means that memory containing a MX_VECTOR can be safely realloc'd and MX_VECTOR can be used inside another MXVECTOR.

Here is a simple example for doubles but the same concept applies to all bit-copy-correct types.

size_t i;
MX_VECTOR(double) dvect;

mx_vector(&dvect);
mx_vector_resize(&dvect, 100);

for (i=0; i < mx_vector_size(&dvect); i++)
   dvect.data[i] = i;
   
mx_vector_free(&dvect);
NOTE: All of the mx_vector* functions are in fact macros that may evaluate the arguments (the vector) more than once. This is especially true for the vector itself (the first argument) and any pointer arguments. Efforts have been made to evaluate other arguments only once. So modifiying arguments in the macro like this:
mx_vector_resize(&dvect, n++);
will work as expected. However code like this:
mx_vector_resize(vectptr++, n);
will not work as expected. (../include/deds/vector.h)

Part of the deds library.

Generated by MXDOC 2.2 on Sun Feb 4 15:16:26 2007