These functions are declared in the main Allegro header file:

#include <allegro5/allegro.h>

al_malloc

#define al_malloc(n) \
   (al_malloc_with_context((n), __LINE__, __FILE__, __func__))

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

al_free

#define al_free(p) \
   (al_free_with_context((p), __LINE__, __FILE__, __func__))

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

al_realloc

#define al_realloc(p, n) \
   (al_realloc_with_context((p), (n), __LINE__, __FILE__, __func__))

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

al_calloc

#define al_calloc(c, n) \
   (al_calloc_with_context((c), (n), __LINE__, __FILE__, __func__))

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

al_malloc_with_context

void *al_malloc_with_context(size_t n,
   int line, const char *file, const char *func)

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.

al_free_with_context

void al_free_with_context(void *ptr,
   int line, const char *file, const char *func)

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.

al_realloc_with_context

void *al_realloc_with_context(void *ptr, size_t n,
   int line, const char *file, const char *func)

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.

al_calloc_with_context

void *al_calloc_with_context(size_t count, size_t n,
   int line, const char *file, const char *func)

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.

ALLEGRO_MEMORY_INTERFACE

typedef struct ALLEGRO_MEMORY_INTERFACE ALLEGRO_MEMORY_INTERFACE;

This structure has the following fields.

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

al_set_memory_interface

void al_set_memory_interface(ALLEGRO_MEMORY_INTERFACE *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