| Description | The 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:
| X | The 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. |
| size | The size in bytes, up to which the respective vector / matrix will be read or written |
| FlagRW | Bit 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. |
| funcname | A string, containing the name of the function under scrutiny |
V_checkBoundaries identifies the following types of problems and takes the appropriate measures:
| Detected problem | Error message | Further measures |
| X = NULL or nil | FuncName: read / write at address 0000. | Program execution is immediately halted to avoid further damage. |
| size = 0 | FuncName: Function called with size = 0 (must be ≥ 1) | Program execution is immediately halted to avoid further damage. |
| size > VectorSize | FuncName: 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 > RemainingVectorSize | FuncName: 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 / matrix | FuncName: Warning: read / write of unallocated or non-OptiVec vector StartAddress | Program 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. |