V_checkBoundaries
FunctionCheck vector / matrix and associated size parameters for dimension consistency
Syntax C/C++#include <Veclib.h>
void V_checkBoundaries( void *X, ui size, int FlagRW, char *funcname );
Pascal/Delphiuses Veclib;
procedure V_checkBoundaries( X:Pointer; size:UIntSize; FlagRW:Integer; funcname:PChar );
DescriptionThe single-most frequent cause of hard-to-find errors in vector and matrix calculations is dimension mismatch, leading to violations of the vector or matrix boundaries. The resulting corruption of the heap, in turn, usually leads to problems and crashes much later in the program flow, so that it is very difficult to identify the origin of the problem. This is the reason why we developed the dimension-checking debug libraries (VCF4WD.LIB for Borland / CodeGear C++, OVVC4D.LIB for Visual C++, units in LIB4D for Delphi). In these debug libraries, every vector or matrix function of OptiVec calls V_checkBoundaries in order to assert dimension consistency. V_checkBoundaries checks if the allocated size of X is enough for the parameter size which was passed to the respective function. If any irregularity is detected, error and/or warning messages are generated. Thereby, it is made much easier to track and locate the offending code.
Although the primary purpose of this function is its internal use inside the debug libraries of OptiVec, you may call this function also from your own routines for consistency checks.

Input parameters of V_checkBoundaries:
XThe definition as a generalized pointer (void * in C/C++, Pointer in Pascal/Delphi) means that this function will accept any vector or matrix, regardless of type.
sizeThe size in bytes, up to which the respective vector / matrix will be read or written
FlagRWBit 0 of this flag indicates read (0) or write (1). If both read and write will occur for the same vector, write (1) is signaled.
Bit 1 indicates if X is a vector (0) or a matrix (1).
E.g., a vector that will be read only is signaled by FlagRW = 0,  a matrix that will be written is signaled by FlagRW=2+1.
funcnameA string, containing the name of the function under scrutiny
 
V_checkBoundaries identifies the following types of problems and takes the appropriate measures:
Detected problemError messageFurther measures
X = NULL or nilFuncName: read / write at address 0000.Program execution is immediately halted to avoid further damage.
size = 0FuncName: Function called with size = 0 (must be ≥ 1)Program execution is immediately halted to avoid further damage.
size > VectorSizeFuncName: Boundary violation: vector / matrix starting at StartAddress, ending at EndAddress, is read / written up to OffendingAddress.Program execution is continued.
X is a subvector, and size > RemainingVectorSizeFuncName: Boundary violation: subvector / submatrix StartAddress of BasicAddress, ending at EndAddress, is read / written up to OffendingAddress.Program execution is continued.
X not allocated as OptiVec vector / matrixFuncName: Warning: read / write of unallocated or non-OptiVec vector StartAddressProgram execution is continued.
 
In case you have to use static arrays (or arrays dynamic allocated with malloc or the Windows API memory functions) and do not want to see the latter warning message, you may call
V_setBoundaryCheckWarn( 0 );  (C/C++) or
V_setBoundaryCheckWarn( FALSE );  (Pascal / Delphi).
This will switch off only the described warning messages. It does not affect the error messages.

Error handlingnone
Return valuenone
See alsoV_setBoundaryCheckWarn

VectorLib Table of Contents  OptiVec home