[cairo] Using OS/2 memory allocation APIs

Behdad Esfahbod behdad at behdad.org
Mon Nov 19 12:17:40 PST 2007


On Mon, 2007-11-19 at 19:38 -0500, Peter Weilbacher wrote:
> This is something I have tried for Mozilla apps on OS/2. When I use the
> OS/2 APIs to allocate some of the larger buffers for cairo, these are
> given back to the system immediately when freeing them. This apparently
> reduces memory fragmentation a lot compared to using standard C functions,
> so I would really like to get this in.
> 
> The attached patch leaves the standard functions in place (as the default
> option on compilation) because using DosAllocMem() is not desirable for
> all programs (it has some extra memory overhead that would be noticeable
> for smaller programs).
> 
> I thought of replacing the Vlad's _cairo_malloc macros with something like
> this for OS/2, so that other parts of the code could also benefit from
> this. But I think I would actually convert the macros to functions then
> because this API returns the allocated memory pointer in an argument
> instead of the return value. So in principle I'm asking, if the attached
> patch would be good to push (sorry, it's against the Mozilla CVS version,
> can't access git right now). I was also thinking about adding similar
> #ifdefs in cairo-pdf-surface.c, cairo-image-surface.c , and pixman-image.c
> for the pixel buffers that are allocated and freed there...
> 
>     Peter.

Hi Peter,

If you ask me, there's no way to get that in cairo.  It's just plain
ugly and totally against cairo's coding standards.  If it didn't need a
different free function there was some hope of doing it, but with a
separate free() I don't think so.

If we go ahead and do add that, one can request a similar change for
Linux to use mmap for large allocations.  Probably similar stuff exist
on other platforms too.  But I think we should just leave that to libc
hackers.  OS/2 is no exception IMO.

Sorry about that.

Regards,
-- 
behdad
http://behdad.org/

"Those who would give up Essential Liberty to purchase a little
 Temporary Safety, deserve neither Liberty nor Safety."
        -- Benjamin Franklin, 1759





More information about the cairo mailing list