[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 12:43:08 -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 12:39 PM, Eric Blake wrote:
> On 2/8/19 11:26 AM, Peng Yu wrote:
>>> Come on. If you're not going to read the code, at least read the comments.
>> This is what I don't understand. Why caching pointers not caching the
>> actual memory allocated to the string can improve the performance?
>>> /* Create an object cache C of N pointers to OTYPE. */
>>> /* Free all cached items, which are pointers to OTYPE, in object cache C. */
> A cache of pointers means that the next time you need a fresh pointer to
> the same object type, you can reuse the allocated memory still pointed
> to by an older pointer already found in the cache (fast) rather than
> having to call malloc() (slow).  Since all of the pointers are pointing
> to memory of the same size (namely, sizeof(OTYPE)), you don't have to
> worry about whether your reuse of the area is going to overwrite more
> memory than the previous use of that area.
> Apparently, you are confused on the data type being cached - it is NOT a
> cache of the user-supplied strings, but of the WORD_DESC and WORD_LIST
> structures used to manage groups of user-supplied strings.  While we
> have to eat the cost of malloc()ing user-supplied strings of unknown
> lengths, the cache at least lets us avoid even more malloc()s of the
> fixed-size management data structures.

I would add that WORD_DESCs and WORD_LISTs are by far the most-used shell
data objects.

``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/

Attachment: signature.asc
Description: OpenPGP digital signature

reply via email to

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