CCP4 Coordinate Library Project

Object interface: Initialization, Memory Allocation and Miscellaneous Functions.

On most systems, the Library does not need any special initialization. Some (hopefully obsolete) C++ environments however fail to initialize static variables. All vital static variables in the Library may be forcefully initialized by calling function InitMatType.

It is important to keep in mind that through the Library, a pointer is considered as allocated unless it has value "NULL". The Library may attempt to deallocate any pointer which is not set "NULL". If a pointer was obtained from a Library function, the Library normally is responsible for deallocation of it (exceptions from this rule are mentioned wherever necessary); therefore the application should not attempt to change such pointer in any way. If an allocated pointer was given to a Library function and is then returned as a result, it may appear reallocated or even deallocated - check remarks for that Library function.

Finally, the Library provides various tools for working with dynamically allocated objects such as vectors and matrices. Using them is encouraged, although is not mandatory.

Function Purpose
InitMatType Initialization of static variables.
GetVectorMemory Allocating a vector object.
FreeVectorMemory Deallocating a vector object.
GetMatrixMemory Allocating a matrix object.
FreeMatrixMemory Deallocating a matrix object.
GetMatrix3Memory Allocating a 3D matrix object.
FreeMatrix3Memory Deallocating a 3D matrix object.


Boolean InitMatType ( 
 )
PURPOSE
Initialization of static variables.
DESCRIPTION

This function performs initialization of vital data kept in Library's static fields. Using it is necessary only in certain C++ environments, which fail to perform the initialization automatically. It is absolutely cheap and completely harmless to call this function multiple times, however an application needs to call it only once from the application's top.


RETURN

The function always returns True, there is no need to check on it.


Boolean GetVectorMemory ( 
vectortype &  V, 
word N,
word Shift )
PURPOSE
Allocating a vector object.
ARGUMENTS
vectortype & V
A vector object. Overloaded instances of this function work with real vectors (type rvector), integer vectors (ivector), word vectors (wvector), byte and logical vectors (bvector), long integer vectors (lvector) and character string vectors (psvector). See definition of these types in Mathematical Types.

word N
Required length of the vector.

word Shift
Requred offset of the vector. This parameter has default value of 1.

DESCRIPTION

The function allocates N elements of type *V, shifts them according to the value of Shift and returns as allocated vector V. As a result, the vector elements are accessible as V[i] where i ranges as [Shift ... Shift+N-1].


RETURN

The function returns True if memory was successfully allocated, and False otherwise. If allocation fails, V returns NULL.

NOTE 1: This function does not check if V was previously allocated and does not try to deallocate it. It is responsibility of the application to deallocate V prior calling GetVectorMemory, if necessary.

NOTE 2: This function does not initialize the allocated memory.


void FreeVectorMemory ( 
vectortype &  V, 
word Shift )
PURPOSE
Deallocating a vector object.
ARGUMENTS
vectortype & V
A vector object. Overloaded instances of this function work with real vectors (type rvector), integer vectors (ivector), word vectors (wvector), byte and logical vectors (bvector), long integer vectors (lvector) and character string vectors (psvector). See definition of these types in Mathematical Types.

word Shift
Offset of the vector that was used at allocation. This parameter has default value of 1.

DESCRIPTION

The function checks if vector V was allocated, and if it was, deallocates it. V always returns NULL.

NOTE 1: The value of Shift must be the same as that used at allocation of the vector. If this condition does not hold, the application may crash in unpredictable place.

NOTE 2: It is perfectly Ok to give V=NULL to this function.


Boolean GetMatrixMemory ( 
matrixtype &  A, 
word N,
word M,
word ShiftN,
word ShiftM )
PURPOSE
Allocating a matrix object.
ARGUMENTS
matrixtype & A
A matrix object. Overloaded instances of this function work with real matrices (type rmatrix), integer matrices (imatrix), word matrices (wmatrix), byte and logical matrices (bmatrix), long integer matrices (lmatrix) and character string matrices (psmatrix). See definition of these types in Mathematical Types.

word N
Required "vertical" (first-index) dimension of the matrix.

word M
Required "horizontal" (second-index) dimension of the matrix.

word ShiftN
Requred "vertical" (first-index) offset of the matrix. This parameter has default value of 1.

word ShiftM
Requred "horizontal" (second-index) offset of the matrix. This parameter has default value of 1.

DESCRIPTION

The function returns matrix A allocated as N elements of type *A, shifted by the value of ShiftN, each of them allocated as vectors of length M with offset ShiftM. As a result, the matrix' elements are accessible as A[i][j] where index i ranges as [ShiftN ... ShiftN+N-1] and index j - as [ShiftM ... ShiftM+M-1].


RETURN

The function returns True if memory was successfully allocated, and False otherwise. If allocation fails, A returns NULL.

NOTE 1: This function does not check if A was previously allocated and does not try to deallocate it. It is responsibility of the application to deallocate A prior calling GetMatrixMemory, if necessary.

NOTE 2: This function does not initialize the allocated memory.


void FreeMatrixMemory ( 
matrixtype &  A, 
word N,
word ShiftN,
word ShiftM )
PURPOSE
Deallocating a matrix object.
ARGUMENTS
matrixtype & A
A matrix object. Overloaded instances of this function work with real matrices (type rmatrix), integer matrices (imatrix), word matrices (wmatrix), byte and logical matrices (bmatrix), long integer matrices (lmatrix) and character string matrices (psmatrix). See definition of these types in Mathematical Types.

word N
The "vertical" (first-index) dimension, used at allocation of the matrix.

word ShiftN
The "vertical" (first-index) offset, used at allocation of the matrix. This parameter has default value of 1.

word ShiftM
The "horizontal" (second-index) offset, used at allocation of of the matrix. This parameter has default value of 1.

DESCRIPTION

The function checks if matrix A was allocated, and if it was, deallocates it. A always returns NULL.

NOTE 1: The values of N, ShiftN and ShiftM must be same as those used at allocation of the matrix. If this condition does not hold, the application may crash in unpredictable place.

NOTE 2: It is perfectly Ok to give A=NULL to this function.


Boolean GetMatrix3Memory ( 
matrix3type &  A, 
word N,
word M,
word K,
word ShiftN,
word ShiftM,
word ShiftK )
PURPOSE
Allocating a 3D matrix object.
ARGUMENTS
matrix3type & A
A 3D matrix object. Overloaded instances of this function work with real 3D matrices (type rmatrix3), integer 3D matrices (imatrix3), word 3D matrices (wmatrix3), byte and logical 3D matrices (bmatrix3), long integer 3D matrices (lmatrix3) and character string 3D matrices (psmatrix3). See definition of these types in Mathematical Types.

word N
Required "vertical" (first-index) dimension of the matrix.

word M
Required "horizontal" (second-index) dimension of the matrix.

word K
Required "depth" (third-index) dimension of the matrix.

word ShiftN
Requred "vertical" (first-index) offset of the matrix. This parameter has default value of 1.

word ShiftM
Requred "horizontal" (second-index) offset of the matrix. This parameter has default value of 1.

word ShiftK
Requred "depth" (third-index) offset of the matrix. This parameter has default value of 1.

DESCRIPTION

The function returns 3D matrix A allocated as N elements of type *A, shifted by the value of ShiftN, each of them allocated as matrices of "vertical" dimension/offset M/ShiftM and "horizontal" dimension/offset K/ShiftK. As a result, the matrix' elements are accessible as A[i][j][k] where index i ranges as [ShiftN ... ShiftN+N-1], index j - as [ShiftM ... ShiftM+M-1] and index k - as [ShiftK ... ShiftK+K-1].


RETURN

The function returns True if memory was successfully allocated, and False otherwise. If allocation fails, A returns NULL.

NOTE 1: This function does not check if A was previously allocated and does not try to deallocate it. It is responsibility of the application to deallocate A prior calling GetMatrix3Memory, if necessary.

NOTE 2: This function does not initialize the allocated memory.


void FreeMatrix3Memory ( 
matrix3type &  A, 
word N,
word M,
word ShiftN,
word ShiftM,
word ShiftK )
PURPOSE
Deallocating a 3D matrix object.
ARGUMENTS
matrix3type & A
A matrix object. Overloaded instances of this function work with real matrices (type rmatrix3), integer matrices (imatrix3), word matrices (wmatrix3), byte and logical matrices (bmatrix3), long integer matrices (lmatrix3) and character string matrices (psmatrix3). See definition of these types in Mathematical Types.

word N
The "vertical" (first-index) dimension, used at allocation of the matrix.

word M
The "horizontal" (second-index) dimension, used at allocation of the matrix.

word ShiftN
The "vertical" (first-index) offset, used at allocation of the matrix. This parameter has default value of 1.

word ShiftM
The "horizontal" (second-index) offset, used at allocation of of the matrix. This parameter has default value of 1.

word ShiftK
The "depth" (third-index) offset, used at allocation of of the matrix. This parameter has default value of 1.

DESCRIPTION

The function checks if 3D matrix A was allocated, and if it was, deallocates it. A always returns NULL.

NOTE 1: The values of N, M, ShiftN, ShiftM and ShiftK must be same as those used at allocation of the matrix. If this condition does not hold, the application may crash in unpredictable place.

NOTE 2: It is perfectly Ok to give A=NULL to this function.



Back to index