ajmem.c


Function ajMemAlloc

Allocates memory using malloc, and fails with an error message if unsuccessful.

Synopsis

Prototype
void* ajMemAlloc (
      size_t nbytes,
      const char* file,
      ajint line,
      AjBool nofail
);

TypeNameRead/WriteDescription
size_tnbytesInputNumber of bytes required
const char*fileInputSource file name, generated by a macro.
ajintlineInputSource line number, generated by a macro.
AjBoolnofailInputIf true, return with a NULL pointer when unable to allocate.
void* RETURNSuccessfully allocated memory, or NULL on failure. Normal behaviour is to raise an exception and fail, or if running with Java, to print to standard error and exit.

Input
nbytes:(Input)Number of bytes required
file:(Input)Source file name, generated by a macro.
line:(Input)Source line number, generated by a macro.
nofail:(Input)If true, return with a NULL pointer when unable to allocate.
Returns
void*:Successfully allocated memory, or NULL on failure. Normal behaviour is to raise an exception and fail, or if running with Java, to print to standard error and exit.

Description

Allocates memory using malloc, and fails with an error message if unsuccessful.

See Also

See other functions in this section

Availability

In release 6.4.0

Function ajMemCalloc

Allocates memory using calloc for an array of elements, and fails with an error message if unsuccessful.

Synopsis

Prototype
void* ajMemCalloc (
      size_t count,
      size_t nbytes,
      const char* file,
      ajint line,
      AjBool nofail
);

TypeNameRead/WriteDescription
size_tcountInputNumber of elements required
size_tnbytesInputNumber of bytes required per element
const char*fileInputSource file name, generated by a macro.
ajintlineInputSource line number, generated by a macro.
AjBoolnofailInputIf true, return with a NULL pointer when unable to allocate.
void* RETURNSuccessfully allocated memory, or NULL on failure. Normal behaviour is to raise an exception and fail, or if running with Java, to print to standard error and exit.

Input
count:(Input)Number of elements required
nbytes:(Input)Number of bytes required per element
file:(Input)Source file name, generated by a macro.
line:(Input)Source line number, generated by a macro.
nofail:(Input)If true, return with a NULL pointer when unable to allocate.
Returns
void*:Successfully allocated memory, or NULL on failure. Normal behaviour is to raise an exception and fail, or if running with Java, to print to standard error and exit.

Description

Allocates memory using calloc for an array of elements, and fails with an error message if unsuccessful.

See Also

See other functions in this section

Availability

In release 6.4.0

Function ajMemCallocZero

Allocates memory using calloc for an array of elements, and fails with an error message if unsuccessful.

The memory is initialised to zero. This should be done by the standard calloc function. It is explicitly done here to make sure.

Synopsis

Prototype
void* ajMemCallocZero (
      size_t count,
      size_t nbytes,
      const char* file,
      ajint line,
      AjBool nofail
);

TypeNameRead/WriteDescription
size_tcountInputNumber of elements required
size_tnbytesInputNumber of bytes required
const char*fileInputSource file name, generated by a macro.
ajintlineInputSource line number, generated by a macro.
AjBoolnofailInputIf true, return with a NULL pointer when unable to allocate.
void* RETURNSuccessfully allocated memory, or NULL on failure. Normal behaviour is to raise an exception and fail, or if running with Java, to print to standard error and exit.

Input
count:(Input)Number of elements required
nbytes:(Input)Number of bytes required
file:(Input)Source file name, generated by a macro.
line:(Input)Source line number, generated by a macro.
nofail:(Input)If true, return with a NULL pointer when unable to allocate.
Returns
void*:Successfully allocated memory, or NULL on failure. Normal behaviour is to raise an exception and fail, or if running with Java, to print to standard error and exit.

Description

Allocates memory using calloc for an array of elements, and fails with an error message if unsuccessful.

The memory is initialised to zero. This should be done by the standard calloc function. It is explicitly done here to make sure.

See Also

See other functions in this section

Availability

In release 6.4.0

Function ajMemSetZero

Zeroes memory for an array of elements,

Synopsis

Prototype
void ajMemSetZero (
      void* ptr,
      size_t count,
      size_t nbytes
);

TypeNameRead/WriteDescription
void*ptrModifyPointer to memory previously allocated with 'malloc'
size_tcountInputNumber of elements required
size_tnbytesInputNumber of bytes required
void RETURN

Input
count:(Input)Number of elements required
nbytes:(Input)Number of bytes required
Input & Output
ptr:(Modify)Pointer to memory previously allocated with 'malloc'
Returns
void:No return value

Description

Zeroes memory for an array of elements,

See Also

See other functions in this section

Availability

In release 6.4.0

Function ajMemFree

Frees memory using 'free' and zeroes the pointer. Ignores NULL (uninitialised) pointers.

Synopsis

Prototype
void ajMemFree (
      void** ptr
);

Input & Output
TypeNameRead/WriteDescription
void**ptrModifyPointer to memory previously allocated with 'malloc'
ptr:(Modify)Pointer to memory previously allocated with 'malloc'

Description

Frees memory using 'free' and zeroes the pointer. Ignores NULL (uninitialised) pointers.

See Also

See other functions in this section

Availability

In release 6.4.0

Function ajMemResize

Resizes previously allocated memory, and ensures data is copied to the new location if it is moved.

If the pointer is new then new memory is allocated automatically.

The C run-time library function realloc does preserve existing values but does not initialise any memory after the old contents.

Synopsis

Prototype
void* ajMemResize (
      void* ptr,
      size_t nbytes,
      const char* file,
      ajint line,
      AjBool nofail
);
void*ptrModifyPointer to memory previously allocated with 'malloc' size_tnbytesInputNumber of bytes required const char*fileInputSource file name, generated by a macro. ajintlineInputSource line number, generated by a macro. AjBoolnofailInputIf true, return with a NULL pointer when unable to allocate. void* RETURNSuccessfully reallocated memory, or NULL on failure. Normal behaviour is to raise an exception and fail, or if running with Java, to print to standard error and exit.

Input
nbytes:(Input)Number of bytes required
file:(Input)Source file name, generated by a macro.
line:(Input)Source line number, generated by a macro.
nofail:(Input)If true, return with a NULL pointer when unable to allocate.
Input & Output
ptr:(Modify)Pointer to memory previously allocated with 'malloc'
Returns
void*:Successfully reallocated memory, or NULL on failure. Normal behaviour is to raise an exception and fail, or if running with Java, to print to standard error and exit.

Description

Resizes previously allocated memory, and ensures data is copied to the new location if it is moved.

If the pointer is new then new memory is allocated automatically.

The C run-time library function realloc does preserve existing values but does not initialise any memory after the old contents.

See Also

See other functions in this section

Availability

In release 6.4.0

Function ajMemResizeZero

Resizes previously allocated memory, and ensures data is copied to the new location if it is moved.

If the pointer is new then new memory is allocated automatically.

Memory beyond the previous contents is initialised to zero

The C run-time library function realloc does preserves existing values but does not initialise any memory after the old contents. This is why this function needs to be told what the old size was.

Synopsis

Prototype
void* ajMemResizeZero (
      void* ptr,
      size_t oldbytes,
      size_t nbytes,
      const char* file,
      ajint line,
      AjBool nofail
);

TypeNameRead/WriteDescription
void*ptrModifyPointer to memory previously allocated with 'malloc'
size_toldbytesInputNumber of bytes required
size_tnbytesInputNumber of bytes required
const char*fileInputSource file name, generated by a macro.
ajintlineInputSource line number, generated by a macro.
AjBoolnofailInputIf true, return with a NULL pointer when unable to allocate.
void* RETURNSuccessfully reallocated memory, or NULL on failure. Normal behaviour is to raise an exception and fail, or if running with Java, to print to standard error and exit.

Input
oldbytes:(Input)Number of bytes required
nbytes:(Input)Number of bytes required
file:(Input)Source file name, generated by a macro.
line:(Input)Source line number, generated by a macro.
nofail:(Input)If true, return with a NULL pointer when unable to allocate.
Input & Output
ptr:(Modify)Pointer to memory previously allocated with 'malloc'
Returns
void*:Successfully reallocated memory, or NULL on failure. Normal behaviour is to raise an exception and fail, or if running with Java, to print to standard error and exit.

Description

Resizes previously allocated memory, and ensures data is copied to the new location if it is moved.

If the pointer is new then new memory is allocated automatically.

Memory beyond the previous contents is initialised to zero

The C run-time library function realloc does preserves existing values but does not initialise any memory after the old contents. This is why this function needs to be told what the old size was.

See Also

See other functions in this section

Availability

In release 6.4.0

Function ajMemArrB

Creates an AjBool array. Use AJFREE to free the memory when no longer needed.

Synopsis

Prototype
ajint* ajMemArrB (
      size_t size
);

TypeNameRead/WriteDescription
size_tsizeInputNumber of array elements.
ajint* RETURNNewly allocated array.

Input
size:(Input)Number of array elements.
Returns
ajint*:Newly allocated array.

Description

Creates an AjBool array. Use AJFREE to free the memory when no longer needed.

See Also

See other functions in this section

Availability

In release 6.4.0

Function ajMemArrI

Creates an integer array. Use AJFREE to free the memory when no longer needed.

Synopsis

Prototype
ajint* ajMemArrI (
      size_t size
);

TypeNameRead/WriteDescription
size_tsizeInputNumber of array elements.
ajint* RETURNNewly allocated array.

Input
size:(Input)Number of array elements.
Returns
ajint*:Newly allocated array.

Description

Creates an integer array. Use AJFREE to free the memory when no longer needed.

See Also

See other functions in this section

Availability

In release 6.4.0

Function ajMemArrF

Creates a float array. Use AJFREE to free the memory when no longer needed.

Synopsis

Prototype
float* ajMemArrF (
      size_t size
);

TypeNameRead/WriteDescription
size_tsizeInputNumber of array elements.
float* RETURNNewly allocated array.

Input
size:(Input)Number of array elements.
Returns
float*:Newly allocated array.

Description

Creates a float array. Use AJFREE to free the memory when no longer needed.

See Also

See other functions in this section

Availability

In release 6.4.0

Function ajMemStat

Prints a summary of memory usage with debug calls

Synopsis

Prototype
void ajMemStat (
      const char* title
);

TypeNameRead/WriteDescription
const char*titleInputTitle for this summary
void RETURN

Input
title:(Input)Title for this summary
Returns
void:No return value

Description

Prints a summary of memory usage with debug calls

See Also

See other functions in this section

Availability

In release 6.4.0

Function ajMemExit

Prints a summary of memory usage with debug calls

Synopsis

Prototype
void ajMemExit (
      void
);

TypeNameRead/WriteDescription
void RETURN

Returns
void:No return value

Description

Prints a summary of memory usage with debug calls

See Also

See other functions in this section

Availability

In release 6.4.0

Function ajMemCheck

Prints a message appropriate to the memcheck status

Synopsis

Prototype
void ajMemCheck (
      int istat
);

TypeNameRead/WriteDescription
intistatInputEnumerated value from mprobe
void RETURN

Input
istat:(Input)Enumerated value from mprobe
Returns
void:No return value

Description

Prints a message appropriate to the memcheck status

See Also

See other functions in this section

Availability

In release 6.4.0

Function ajMemCheckSetLimit

Prints a message appropriate to the memcheck status

Synopsis

Prototype
void ajMemCheckSetLimit (
      ajint maxfail
);

TypeNameRead/WriteDescription
ajintmaxfailInputMaximum failures allowed
void RETURN

Input
maxfail:(Input)Maximum failures allowed
Returns
void:No return value

Description

Prints a message appropriate to the memcheck status

See Also

See other functions in this section

Availability

In release 6.4.0

Function ajMemProbe

Probes a memory location for possible errors

Synopsis

Prototype
void ajMemProbe (
      void* ptr,
      const char* file,
      ajint line
);

TypeNameRead/WriteDescription
void*ptrModifyPointer to memory previously allocated with 'malloc'
const char*fileInputSource file name, generated by a macro.
ajintlineInputSource line number, generated by a macro.
void RETURN

Input
file:(Input)Source file name, generated by a macro.
line:(Input)Source line number, generated by a macro.
Input & Output
ptr:(Modify)Pointer to memory previously allocated with 'malloc'
Returns
void:No return value

Description

Probes a memory location for possible errors

See Also

See other functions in this section

Availability

In release 6.4.0