# Memory management routines

These functions are declared in the main Allegro header file:

~~~~c
 #include <allegro5/allegro.h>
~~~~

## API: al_malloc

Like malloc() in the C standard library, but the implementation may be
overridden.

This is a macro.

See also: [al_free], [al_realloc], [al_calloc], [al_malloc_with_context],
[al_set_memory_interface]

## API: al_free

Like free() in the C standard library, but the implementation may be
overridden.

Additionally, on Windows, a memory block allocated by one DLL must be freed
from the same DLL.  In the few places where an Allegro function returns a
pointer that must be freed, you must use [al_free] for portability to Windows.

This is a macro.

See also: [al_malloc], [al_free_with_context]

## API: al_realloc

Like realloc() in the C standard library, but the implementation may be
overridden.

This is a macro.

See also: [al_malloc], [al_realloc_with_context]

## API: al_calloc

Like calloc() in the C standard library, but the implementation may be
overridden.

This is a macro.

See also: [al_malloc], [al_calloc_with_context]

## API: al_malloc_with_context

This calls malloc() from the Allegro library (this matters on Windows),
unless overridden with [al_set_memory_interface],

Generally you should use the [al_malloc] macro.

## API: al_free_with_context

This calls free() from the Allegro library (this matters on Windows),
unless overridden with [al_set_memory_interface].

Generally you should use the [al_free] macro.

## API: al_realloc_with_context

This calls realloc() from the Allegro library (this matters on Windows),
unless overridden with [al_set_memory_interface],

Generally you should use the [al_realloc] macro.

## API: al_calloc_with_context

This calls calloc() from the Allegro library (this matters on Windows),
unless overridden with [al_set_memory_interface],

Generally you should use the [al_calloc] macro.

## API: ALLEGRO_MEMORY_INTERFACE

This structure has the following fields.

~~~~c
void *(*mi_malloc)(size_t n, int line, const char *file, const char *func);
void (*mi_free)(void *ptr, int line, const char *file, const char *func);
void *(*mi_realloc)(void *ptr, size_t n, int line, const char *file,
                    const char *func);
void *(*mi_calloc)(size_t count, size_t n, int line, const char *file,
                   const char *func);
~~~~

See also: [al_set_memory_interface]

## API: al_set_memory_interface

Override the memory management functions with implementations of
[al_malloc_with_context], [al_free_with_context], [al_realloc_with_context] and
[al_calloc_with_context].  The context arguments may be used for debugging.

If the pointer is NULL, the default behaviour will be restored.

See also: [ALLEGRO_MEMORY_INTERFACE]

