Name
- wvNewMatrixShareArray - create a new matrix that shares memory with a C
(multi-dimensional) array.
Synopsis
-
#include <wv/matrix.h>
WVmatrix *wvNewMatrixShareArray(const WVindexVector *size, WVdata *array);
Description
-
wvNewMatrixShareArray returns a matrix of size.
The matrix will hold the same data as the array, provided the
array is the same size.
The array is passed as a pointer to the first element in the
C array (see the example).
Example
-
#include <wv/matrix.h>
.
.
.
{
WVindexVector *size;
WVmatrix *mat;
WVdata initVal[3][4] = {
{ 0, 3, 4, 0 },
{ 0, 0, 2, 3 },
{-1, 1,-3, 0 } };
size = wvVaNewIndexVector(2, 3, 4);
mat = wvNewMatrixShareArray(size, &(initVal[0][0]));
.
.
.
wvDestroyMatrix(mat);
wvDestroyIndexVector(size);
}
Note
- When the matrix created with wvNewMatrixShareArray is destroyed,
the memory it shares with the C array is not freed (since it wasn't
allocated by the wv library).
See Also
-
wvNewMatrix(3)
Diagnostics
- A NULL pointer is returned if the request cannot be completed (usually
indicating that the process has run out of memory).
Caveat
- If the C array is not the same size, the results are undefined.
|