|
[A5]use custom memory allocator in allegro carefully |
vkensou
Member #15,546
March 2014
|
if you use custom memory allocator to replace allegro's default allocator,plz be careful. before use the method al_set_memory_interface(), allegro use default allocator to malloc/free.So you need al_set_memory_interface before allegro install. Even if you do so, or have an opportunity to cause a memory leak. like this: 1#include <xxx.h>
2
3String str("test");
this string's memory is malloc before the main(), use the default malloc. so you must use default free() to free it. that mean you need use al_set_memory_interface() again, after allegro uninstall, to replace your custom allocator with default. so ,don't use al_init(), that method will automatic call al_uninstall_system after main(). 1int main()
2{
3 al_set_memory_interface(&yourallocator);
4 al_install_system(ALLEGRO_VERSION_INT, 0);
5
6 ...your game codes
7
8 al_uninstall_system();
9 al_set_memory_interface(0);
10}
hope help you.;D |
Thomas Fjellstrom
Member #476
June 2000
|
Those are some good points We should probably include them in the documentation, assuming they aren't already. That point about the statically allocated object is a very good one, as it can affect more than just memory management. If you try to call allegro API functions in that object's constructor, things can go horribly wrong. -- |
vkensou
Member #15,546
March 2014
|
thank you for your reply. hope it could help someone else |
Gideon Weems
Member #3,925
October 2003
|
Thomas Fjellstrom
Member #476
June 2000
|
Send a patch to the mailing list (via webmail) or attach to a post on the Allegro Developement forum subsection. -- |
Elias
Member #358
May 2000
|
You can also edit the documentation online at https://github.com/liballeg/allegro5/blob/5.1/docs/src/refman/memory.txt (And then submit with "Pull Request".) -- |
|