VirtualBox

Changeset 26416 in vbox for trunk/include


Ignore:
Timestamp:
Feb 10, 2010 4:32:22 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
57519
Message:

RTMemCache: Initial coding (completely untested).

Location:
trunk/include/iprt
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/err.h

    r26369 r26416  
    12051205/** @} */
    12061206
     1207/** @name RTMemCache status codes
     1208 * @{ */
     1209/** Reached the max cache size. */
     1210#define VERR_MEM_CACHE_MAX_SIZE                 (-855)
     1211/** @} */
     1212
    12071213/** @name RTS3 status codes
    12081214 * @{ */
  • trunk/include/iprt/memcache.h

    r26341 r26416  
    44
    55/*
    6  * Copyright (C) 2006-2007 Sun Microsystems, Inc.
     6 * Copyright (C) 2006-2010 Sun Microsystems, Inc.
    77 *
    88 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    4747 */
    4848
    49 /** @todo Specify and implement RTMemCache. (This header is just a reminder.) */
     49/** A memory cache handle. */
     50typedef R3R0PTRTYPE(struct RTMEMCACHEINT *)     RTMEMCACHE;
     51/** Pointer to a memory cache handle. */
     52typedef RTMEMCACHE                             *PRTMEMCACHE;
     53/** Nil memory cache handle. */
     54#define NIL_RTMEMCACHE                          ((RTMEMCACHE)0)
    5055
     56
     57/**
     58 * Object constructor.
     59 *
     60 * This is called for when an element is allocated for the first time.
     61 *
     62 * @returns IPRT status code.
     63 * @param   hMemCache           The cache handle.
     64 * @param   pvObj               The memory object that should be initialized.
     65 * @param   pvUser              The user argument.
     66 *
     67 * @remarks No serialization is performed.
     68 */
     69typedef DECLCALLBACK(int) FNMEMCACHECTOR(RTMEMCACHE hMemCache, void *pvObj, void *pvUser);
     70/** Pointer to an object constructor for the memory cache. */
     71typedef FNMEMCACHECTOR *PFNMEMCACHECTOR;
     72
     73/**
     74 * Object destructor.
     75 *
     76 * This is called when we're shrinking or destroying the cache.
     77 *
     78 * @param   hMemCache           The cache handle.
     79 * @param   pvObj               The memory object that should be initialized.
     80 * @param   pvUser              The user argument.
     81 *
     82 * @remarks No serialization is performed.
     83 */
     84typedef DECLCALLBACK(void) FNMEMCACHEDTOR(RTMEMCACHE hMemCache, void *pvObj, void *pvUser);
     85/** Pointer to an object destructor for the memory cache. */
     86typedef FNMEMCACHEDTOR *PFNMEMCACHEDTOR;
     87
     88
     89/**
     90 * Create an allocation cache for fixed size memory objects.
     91 *
     92 * @returns IPRT status code.
     93 * @param   phMemCache          Where to return the cache handle.
     94 * @param   cbObject            The size of one memory object.
     95 * @param   cbAlignment         The object alignment.  This must be a power of
     96 *                              two.  The higest alignment is 64.  If set to 0,
     97 *                              a sensible alignment value will be derived from
     98 *                              the object size.
     99 * @param   cMaxObjects         The maximum cache size.  Pass UINT32_MAX if unsure.
     100 * @param   pfnCtor             Object constructor callback.  Optional.
     101 * @param   pfnDtor             Object destructor callback.  Optional.
     102 * @param   pvUser              User argument for the two callbacks.
     103 */
     104RTDECL(int)     RTMemCacheCreate(PRTMEMCACHE phMemCache, size_t cbObject, uint32_t cMaxObjects,
     105                                 PFNMEMCACHECTOR pfnCtor, PFNMEMCACHEDTOR pfnDtor, void *pvUser);
     106
     107/**
     108 * Destroy a cache destroying and freeing allocated memory.
     109 *
     110 * @returns IPRT status code.
     111 * @param   hMemCache       The cache handle.  NIL is quietly (VINF_SUCCESS)
     112 *                          ignored.
     113 */
     114RTDECL(int)     RTMemCacheDestroy(RTMEMCACHE hMemCache);
     115
     116/**
     117 * Allocate an object.
     118 *
     119 * @returns Pointer to the allocated cache object.
     120 * @param   hMemCache           The cache handle.
     121 */
     122RTDECL(void *)  RTMemCacheAlloc(RTMEMCACHE hMemCache);
     123
     124/**
     125 * Allocate an object and return a proper status code.
     126 *
     127 * @returns IPRT status code.
     128 * @retval  VERR_MEM_CACHE_MAX_SIZE if we've reached maximum size (see
     129 *          RTMemCacheCreate).
     130 * @retval  VERR_NO_MEMORY if we failed to allocate more memory for the cache.
     131 *
     132 * @param   hMemCache           The cache handle.
     133 * @param   ppvObj              Where to return the object.
     134 */
     135RTDECL(int)     RTMemCacheAllocEx(RTMEMCACHE hMemCache, void **ppvObj);
     136
     137/**
     138 * Free an object previously returned by RTMemCacheAlloc or RTMemCacheAllocEx.
     139 *
     140 * @param   hMemCache           The cache handle.
     141 * @param   pvObj               The object to free.  NULL is fine.
     142 */
     143RTDECL(void)    RTMemCacheFree(RTMEMCACHE hMemCache, void *pvObj);
    51144
    52145/** @} */
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette