ajmem.c


Function ajMemAlloc

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

Synopsis

Prototype

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

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.

Usage

See source code

Example

In preparation

Errors

See source code

Dependencies

See source code

See Also

See other functions in this section

Availability

In release 3.0.0

Function ajMemCalloc

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

Synopsis

Prototype

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

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.

Usage

See source code

Example

In preparation

Errors

See source code

Dependencies

See source code

See Also

See other functions in this section

Availability

In release 3.0.0

Function ajMemCalloc0

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

The memory is initialised to zero.

Synopsis

Prototype

void* ajMemCalloc0 (
      ajlong count,
      ajlong nbytes,
      const char* file,
      ajint line,
      AjBool nofail
);

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 malloc for an array of elements, and fails with an error message if unsuccessful.

The memory is initialised to zero.

Usage

See source code

Example

In preparation

Errors

See source code

Dependencies

See source code

See Also

See other functions in this section

Availability

In release 3.0.0

Function ajMemFree

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

Synopsis

Prototype

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

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

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

Usage

See source code

Example

In preparation

Errors

See source code

Dependencies

See source code

See Also

See other functions in this section

Availability

In release 3.0.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.

Synopsis

Prototype

void* ajMemResize (
      void* ptr,
      ajlong nbytes,
      const char* file,
      ajint line,
      AjBool nofail
);

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.

Usage

See source code

Example

In preparation

Errors

See source code

Dependencies

See source code

See Also

See other functions in this section

Availability

In release 3.0.0

Function ajMemArrB

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

Synopsis

Prototype

ajint* ajMemArrB (
      size_t size
);

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.

Usage

See source code

Example

In preparation

Errors

See source code

Dependencies

See source code

See Also

See other functions in this section

Availability

In release 3.0.0

Function ajMemArrI

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

Synopsis

Prototype

ajint* ajMemArrI (
      size_t size
);

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.

Usage

See source code

Example

In preparation

Errors

See source code

Dependencies

See source code

See Also

See other functions in this section

Availability

In release 3.0.0

Function ajMemArrF

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

Synopsis

Prototype

float* ajMemArrF (
      size_t size
);

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.

Usage

See source code

Example

In preparation

Errors

See source code

Dependencies

See source code

See Also

See other functions in this section

Availability

In release 3.0.0

Function ajMemStat

Prints a summary of memory usage with debug calls

Synopsis

Prototype

void ajMemStat (
      const char* title
);

Input

title:(Input)Title for this summary

Returns

void:No return value

Description

Prints a summary of memory usage with debug calls

Usage

See source code

Example

In preparation

Errors

See source code

Dependencies

See source code

See Also

See other functions in this section

Availability

In release 3.0.0

Function ajMemExit

Prints a summary of memory usage with debug calls

Synopsis

Prototype

void ajMemExit (
      void
);

Returns

void:No return value

Description

Prints a summary of memory usage with debug calls

Usage

See source code

Example

In preparation

Errors

See source code

Dependencies

See source code

See Also

See other functions in this section

Availability

In release 3.0.0