On 2/8/19 10:52 AM, Peng Yu wrote: > On Fri, Feb 8, 2019 at 9:42 AM Chet Ramey <chet.ra...@case.edu> 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 c...@case.edu http://tiswww.cwru.edu/~chet/