NAME

cxDataMemBoundsCheck - check data object for memory corruption

C SPECIFICATION

#include <cx/DataOps.h>

typedef enum { cx_data_dead, cx_mem_size, cx_mem_bounds, cx_data_ok } cxDataCheckError;

typedef struct { cxDataCheckError error; void *ptr; char *msg;

} cxDataCheckErrorInfo;

cxDataCheckErrorInfo *cxDataMemBoundsCheck(void *data, char *description)

FORTRAN SPECIFICATION

integer cx_data_dead
integer cx_mem_size
integer cx_mem_bounds
integer cx_data_ok

parameter (cx_data_dead = 0) parameter (cx_mem_size = 1) parameter (cx_mem_bounds = 2) parameter (cx_data_ok = 3)

integer function cxDataMemBoundsCheck(data, description) integer data integer description

PARAMETERS

data
Data to be checked.
description
Character string describing where the check is being performed.

DESCRIPTION

cxDataMemBoundsCheck verifies that the memory owned by the data pointed to by data is valid. Extra memory is allocated at the beginning and end of each memory array that the data type contains. A special byte sequence is stored in each of these memory bounds. Common memory usage errors, such as storing values past the end of an array, can be detected easily.

If an error is detected, the cxDataCheckAction defined by cxDataCheckingSet is called, a cxDataCheckErrorInfo structure is returned. Otherwise, a NULL is returned. It is the user's responsibility to destroy the returned error structure using cxDataCheckErrorInfoDel. The contents of the error structure are described in more detail in cxDataCheck. cxDataMemBoundsCheck calls cxDataMagicCheck before doing the memory bounds check.

The memory bounds contains information about the allocated size of the memory. The system flags an error when the memory block is smaller than required, e.g. if the dims vector of a cxLattice was allocated to hold 1 word, but the nDim value is greater than 1. However, it is not an error for the allocated memory to be larger than what is required. This allows data structures to be reduced in size or dimension easily. For example, LatToPyr converts an N-D lattice into a 1-D lattice by duplicating the lattice, then setting nDim to 1 and dims[0] to the product of the previous dimensions. The dims vector only requires 1 word, even though it was allocated to hold N words when the lattice was duplicated.

SEE ALSO

cxDataCheck(3E), cxDataMagicCheck(3E), cxDataCheckErrorInfoDel(3E)
Last modified: Mon Nov 18 13:48:05 GMT 1996
[ Documentation Home ]
© The Numerical Algorithms Group Ltd, Oxford UK. 1996