[Top][All Lists]

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

Re: What is the purpose of wdcache and wlcache?

From: Chet Ramey
Subject: Re: What is the purpose of wdcache and wlcache?
Date: Fri, 8 Feb 2019 11:49:59 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:60.0) Gecko/20100101 Thunderbird/60.5.0

On 2/8/19 10:52 AM, Peng Yu wrote:
> On Fri, Feb 8, 2019 at 9:42 AM Chet Ramey <address@hidden> wrote:
>> On 2/8/19 10:39 AM, Peng Yu wrote:
>>>> Yes: ocache_free.
>>> Could you please help explain what wdcache and wlcache actually do.
>>> Why is it essential to have them? Why not just alloc and free them
>>> without the caches? Thanks.
>> To avoid potentially-expensive calls to malloc and free, the same as
>> any cache.
> There are already many mallocs and frees used in other places in the
> program, why it is essential to use cache here. Is this decision based
> on profiling or it is just based on some abstract concept but without
> actual runtime data?

It was based on profiling at the time I implemented it.

> Where are these parameters coming from?
> #define WDCACHESIZE 128

That's a reasonable size for a cache, and it provided a nice balance
between memory use and speed for the most common cases.

> if ((nbytes) <= 32) {

That's the byte threshold for this implementation of Duff's Device. If
the object is larger than that, it's better to use memset, with whatever
assist the compiler can give you.

> I made the following test program. I don't understand why a longer
> word "xyzabc" can still use the cache. What is actually stored in
> "data"?

Come on. If you're not going to read the code, at least read the comments.

/* Create an object cache C of N pointers to OTYPE. */

/* Free all cached items, which are pointers to OTYPE, in object cache C. */

``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    address@hidden    http://tiswww.cwru.edu/~chet/

reply via email to

[Prev in Thread] Current Thread [Next in Thread]