This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
Re: allocating aligned memory efficiently
- From: "Carlos O'Donell" <carlos at systemhalted dot org>
- To: Joel Dice <joel dot dice at gmail dot com>
- Cc: libc-help at sourceware dot org
- Date: Sat, 20 Feb 2010 17:49:33 -0500
- Subject: Re: allocating aligned memory efficiently
- References: <alpine.DEB.2.00.1002191702330.19193@jdpc.ecovate.com>
On Fri, Feb 19, 2010 at 7:34 PM, Joel Dice <joel.dice@gmail.com> wrote:
> Hi all,
>
> I have a problem which involves allocating memory in chunks, each of a size
> which is a multiple of 64K and each aligned to an address divisible by 64K.
> ?I'd like to make these allocations as memory-efficient as possible,
> minimizing fragmentation and heap management overhead, and I'd like to free
> each one back to the OS promptly when it's no longer needed.
Your last requirement is not honoured by glibc, the allocator attempts
to maximize performance by reusing already mapped blocks of memory, it
does not free them promptly (if ever).
> The posix_memalign(3) and free(3) functions seem to have the semantics I
> want. ?Is this pair the most efficient option for my problem, or would I be
> better off using mmap(2) or some other mechanism?
If you want it free'd back to the OS promptly then I suggest you use
mmap(2) and manage the memory yourself.
Cheers,
Carlos.