[Scummvm-devel] SCI mem functions

Oystein Eftevaag wintermute at geheb.com
Mon Feb 16 18:46:33 CET 2009


Manually wrapping the alloc/dealloc functions like this is pretty error 
prone (easy to forget about), and you'll miss all the allocations done 
in libraries (which can be a good portion).

A generally more robust approach is to hook the functions on the 
operating system level. I.e. setting __malloc_hook in Linux, for example.

This is simple to do, and guarantees you catch all allocations your 
whole process does (in our case, including things like libogg, etc). 
It's how most memory managers work, actually.

This approach is more platform dependent though, of course.

Oh, and as for the reasons:
* To build memory profiles (map out what callstacks allocate how much 
and how often)
* Leak tracing (not too useful given Valgrind and other tools, though)
* Performance (Allocation is relatively expensive. A small-block 
allocator using memory buckets and whatnot can speed things up quite a 
bit, on some platforms).

This may or may not be relevant for ScummVM, of course :)

// Oystein/vinterstum

Filippos Karapetis wrote:
> Hello
>
> While reading through the SCI engine code, I noticed that there are 
> custom definitions of malloc, calloc etc, which can be used to trace 
> memory allocation (in sci/scicore/sci_memory.cpp). The question is: 
> should we adapt this approach in the rest of ScummVM? Or remove these 
> altogether and use "regular" calls to malloc and the like?
>
> Regards
> Filippos
>
> ------------------------------------------------------------------------
> Windows Liveā„¢: E-mail. Chat. Share. Get more ways to connect. See how 
> it works. 
> <http://windowslive.com/howitworks?ocid=TXT_TAGLM_WL_t2_allup_howitworks_022009> 
>
> ------------------------------------------------------------------------
>
> ------------------------------------------------------------------------------
> Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
> -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
> -Strategies to boost innovation and cut costs with open source participation
> -Receive a $600 discount off the registration fee with the source code: SFAD
> http://p.sf.net/sfu/XcvMzF8H
> ------------------------------------------------------------------------
>
> _______________________________________________
> Scummvm-devel mailing list
> Scummvm-devel at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/scummvm-devel
>   





More information about the Scummvm-devel mailing list