Re: memory allocations.



jg pa dec com (Jim Gettys) writes:

> by some care, we arranged to allocate related objects simultaneously
> in a single malloc and reduced the number of calls to malloc by a
> substantial factor (2-3x), while saving the memory overhead as well,
> also saving substantial overhead and improving memory footprint and
> cache behavior, and avoiding fragmentation.

That's what I've done in many places in glibc.  It often pays off even
if it means that you have to do some work twice: first to determine
the size, and then to copy the data.  Sometime you can simplify the
copying by arranging the data in a form which allows easy copying.
This temporary allocation could use single linked lists allocated with
alloca().  The only problem is that one has to know that the input is
reasonably sized to avoid overflowing the stack.

-- 
---------------.                          ,-.   1325 Chesapeake Terrace
Ulrich Drepper  \    ,-------------------'   \  Sunnyvale, CA 94089 USA
Red Hat          `--' drepper at redhat.com   `------------------------



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]