Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » [A5] access to memory management API?

Credits go to BAF, Elias, GullRaDriel, Peter Wang, SiegeLord, and Thomas Fjellstrom for helping out!
This thread is locked; no one can reply to it. rss feed Print
[A5] access to memory management API?
axilmar
Member #1,204
April 2001

I would like to use Allegro's memory API in my program, however the docs do not specify any functions for memory management; only a function for setting the internal functions is specified.

Is there any plan for allowing the user of A5 to use the same functions for memory management?

GullRaDriel
Member #3,861
September 2003
avatar

Your homepage is broken, but that's not the question :-p

What are you calling memory management ? I've never heard of it before.

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

axilmar
Member #1,204
April 2001

A5 contains a function to set the memory management functions:

void al_set_memory_management_functions(
   void *(*malloc)(void *opaque, size_t size),
   void *(*malloc_atomic)(void *opaque, size_t size),
   void (*free)(void *opaque, void *ptr),
   void *(*realloc)(void *opaque, void *ptr, size_t size),
   void *(*debug_malloc)(int line, const char *file, const char *func,
      void *opaque, size_t size),
   void *(*debug_malloc_atomic)(int line, const char *file, const char *func,
      void *opaque, size_t size),
   void (*debug_free)(int line, const char *file, const char *func,
      void *opaque, void *ptr),
   void *(*debug_realloc)(int line, const char *file, const char *func,
      void *opaque, void *ptr, size_t size),
   void *user_opaque);

I'd like to have access to these functions in my A5 library.

My homepage is under construction.

BAF
Member #2,981
December 2002
avatar

That only changes the functions Allegro uses internally to do its management.

Elias
Member #358
May 2000

I think the plan was to expose them with al_malloc and al_free. Nobody made a patch for it so far though.

I also wonder what the "_atomic" means in this context.

--
"Either help out or stop whining" - Evert

SiegeLord
Member #7,827
October 2006
avatar

I too think having a way to access these functions would be useful: for example, the addons can be made to use them too, which seems good in my mind.

Perhaps expose them as the functions themselves? Like al_malloc etc.

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

axilmar
Member #1,204
April 2001

Quote:

That only changes the functions Allegro uses internally to do its management.

Indeed, but here is a scenario: the user that uses A5 and external libraries based on A5 will have a hard time debugging his/her app when it comes to memory management, because the external libraries will not use A5' routines.

Quote:

I also wonder what the "_atomic" means in this context.

A block without pointers. It is a terminology coming from garbage collection. It's nice that A5 specifies this, because memory management functions can be set to gc_malloc/gc_malloc_atomic (of the Boehm GC collector).

Elias
Member #358
May 2000

I see. Should be documented then.

--
"Either help out or stop whining" - Evert

Thomas Fjellstrom
Member #476
June 2000
avatar

Quote:

I see. Should be documented then.

I'm not sure thats what it actually means...

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Elias
Member #358
May 2000

Even more a reason to document it (by whoever knows what it means) :P

--
"Either help out or stop whining" - Evert

Thomas Fjellstrom
Member #476
June 2000
avatar

And currently addons are free to use the AL_MALLOC/AL_FREE macros from aintern_memory.h iirc. I have anyhow.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

axilmar
Member #1,204
April 2001

Is it AL_MALLOC, AL_FREE or al_malloc, al_free?

Peter Wang
Member #23
April 2000

Neither. It currently is _AL_MALLOC/_AL_FREE, but that's for Allegro internal use only (and addons). al_malloc/al_free are planned to be added.

axilmar
Member #1,204
April 2001

Ok...thanks. I will use al_malloc, al_free in my project, which will be a macro for _AL_MALLOC, _AL_FREE. When the memory API will be available, I will remove the macros.

BAF
Member #2,981
December 2002
avatar

What does allegro do in al_mallc/al_free that's so special?

axilmar
Member #1,204
April 2001

It calls the appropriate malloc/free functions set by the function 'al_set_memory_management_functions'.

This is important for debugging.

Thomas Fjellstrom
Member #476
June 2000
avatar

Its important for systems that provide entirely different memory managers for Apps and DLLs (*cough*windows/msvc*cough*).

Passing in the application's memory management functions to Allegro, and all addons using those means everyone is using the same memory manager, and address space.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Go to: