Routines (alphabetical) > Routines: M > MEMORY

# MEMORY

The MEMORY function returns information on the amount of dynamic memory currently in use by the IDL session if no keywords are set. If a keyword is set, MEMORY returns the specified quantity.

Note: This function reports the amount of memory used by IDL’s core process. It does not include memory that is allocated by external libraries.

## Examples

To determine how much dynamic memory is required to execute a sequence of IDL code:

; Get current allocation and reset the high water mark:

start_mem = MEMORY(/CURRENT)

; Arbitrary code goes here.

PRINT, 'Memory required: ', MEMORY(/HIGHWATER) - start_mem

The MEMORY function can also be used in conjunction with DIALOG_MESSAGE as follows:

; Get current dymanic memory in use:
mem = MEMORY(/CURRENT)
; Prepare dialog message:
message = 'Current amount of dynamic memory used is '
sentence = message + STRTRIM(mem,2)+' bytes.'
; Display the dialog message containing memory usage statement:
status = DIALOG_MESSAGE (sentence, /INFORMATION)

## Syntax

Result = MEMORY( [, /CURRENT | , /HIGHWATER | , /NUM_ALLOC | , /NUM_FREE | , /STRUCTURE ] [, /L64] )

## Return Value

The return value is a vector that is always of integer type. The following table describes the information returned if no keywords are set.

Element | Contents
Result[0] | Amount of dynamic memory (in bytes) currently in use by the IDL session.
Result[1] | The number of times IDL has made a memory allocation request from the underlying system.
Result[2] | The number of times IDL has made a request to free memory from the underlying system.
Result[3] | High water mark: The maximum amount of dynamic memory used since the last time the MEMORY function or HELP, /MEMORY procedure was called.

## Arguments

None.

## Keywords

Note: The following keywords determine the return value of the MEMORY function. Except for L64, all of the keywords are mutually exclusive — specify at most one of the following.

### CURRENT

Set this keyword to return the amount of dynamic memory (in bytes) currently in use by the IDL session.

### HIGHWATER

Set this keyword to return the maximum amount of dynamic memory used since the last time the MEMORY function or HELP,/MEMORY procedure was called. This can be used to determine maximum memory use of a code sequence as shown in the example below.

### L64

By default, the result of MEMORY is 32-bit integer when possible, and 64-bit integer if the size of the returned values requires it. Set L64 to force 64-bit integers to be returned in all cases.

Note: Only 64-bit versions of IDL are capable of using enough memory to require 64-bit MEMORY output. Check the value of !VERSION.MEMORY_BITS to see if your IDL is 64-bit or not.

### NUM_ALLOC

Returns the number of times IDL has requested dynamic memory from the underlying system.

### NUM_FREE

Returns the number of times IDL has returned dynamic memory to the underlying system.

### STRUCTURE

Set this keyword to return all available information about Expression in a structure. The result will be an IDL_MEMORY (32-bit) structure when possible, and an IDL_MEMORY64 structure otherwise. Set L64 to force an IDL_MEMORY64 structure to be returned in all cases.

The following are descriptions of the fields in the returned structure:

Field | Description
CURRENT | Current dynamic memory in use.
NUM_ALLOC | Number of calls to allocate memory.
NUM_FREE | Number of calls to free memory.
HIGHWATER | Maximum dynamic memory used since last call for this information.

## Version History

Original | Introduced

## See Also

HELP