[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: Eric Blake
Subject: Re: What is the purpose of wdcache and wlcache?
Date: Fri, 8 Feb 2019 11:39:45 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0

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.

Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

reply via email to

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