Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » why should I use al_malloc() over malloc()?

This thread is locked; no one can reply to it. rss feed Print
why should I use al_malloc() over malloc()?
gentix
Member #14,246
April 2012

The manual says that al_malloc is

manual said:

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

what does that mean? Overriding the implementation with what? Is there a reason I should be using al_malloc? And most importantly, should I be using the al_ memory functions differently from how I use malloc() and friends?

Jeff Bernard
Member #6,698
December 2005
avatar

al_malloc() calls malloc() unless you override the memory management functions with al_set_memory_interface().

--
I thought I was wrong once, but I was mistaken.

Dizzy Egg
Member #10,824
March 2009
avatar

Going out on a limb (or boxing glove), I'm betting gentix is more confused now than pre-post. :-*

----------------------------------------------------
Please check out my songs:
https://soundcloud.com/dont-rob-the-machina

torhu
Member #2,727
September 2002
avatar

It's just that you can override al_malloc and friends with versions that log memory allocations for debugging purposes. In short, it probably doesn't matter either way which you use ;)

If you are curious you can read memory.c and memory.h in Allegro's source, they are short and easy to understand.

Peter Wang
Member #23
April 2000

A few functions require you to use al_malloc or al_free. This will be mentioned in the documentation. Apart from being overridable, the version of malloc/free that Allegro sees may not necessarily match the malloc/free that your program sees.

Go to: