VirtualBox

Changeset 11014 in vbox for trunk/include


Ignore:
Timestamp:
Jul 30, 2008 9:27:50 PM (16 years ago)
Author:
vboxsync
Message:

iprt/RTMemAutoPtr: Some useful destructors (deallocators) and allocators.

File:
1 edited

Legend:

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

    r11011 r11014  
    382382 */
    383383template <class T>
    384 inline void RTMemAutoFree(T *aMem)
     384inline void RTMemAutoDestructor(T *aMem)
    385385{
    386386    RTMemFree(aMem);
     387}
     388
     389
     390/**
     391 * RTMemAutoPtr allocator which uses RTMemTmpAlloc().
     392 *
     393 * @returns Allocated memory on success, NULL on failure.
     394 * @param   pvOld       What to reallocate, shall always be NULL.
     395 * @param   cbNew       The amount of memory to allocate (in bytes).
     396 */
     397inline void *RTMemTmpAutoAllocator(void *pvOld, size_t cbNew)
     398{
     399    AssertReturn(!pvOld, NULL);
     400    return RTMemTmpAlloc(cbNew);
     401}
     402
     403
     404/**
     405 * Template function wrapping RTMemTmpFree to get the correct Destruct
     406 * signature for RTAutoRes.
     407 *
     408 * We can't use a more complex template here, because the g++ on RHEL 3
     409 * chokes on it with an internal compiler error.
     410 *
     411 * @param   T           The data type that's being managed.
     412 * @param   aMem        Pointer to the memory that should be free.
     413 */
     414template <class T>
     415inline void RTMemTmpAutoDestructor(T *aMem)
     416{
     417    RTMemTmpFree(aMem);
     418}
     419
     420
     421
     422/**
     423 * Template function wrapping RTMemEfFree to get the correct Destruct
     424 * signature for RTAutoRes.
     425 *
     426 * We can't use a more complex template here, because the g++ on RHEL 3
     427 * chokes on it with an internal compiler error.
     428 *
     429 * @param   T           The data type that's being managed.
     430 * @param   aMem        Pointer to the memory that should be free.
     431 */
     432template <class T>
     433inline void RTMemEfAutoFree(T *aMem)
     434{
     435    RTMemEfFree(aMem);
    387436}
    388437
     
    423472 *                      This will default to RTMemRealloc.
    424473 */
    425 template <class T, void Destruct(T *) = RTMemAutoFree<T>, void *Allocator(void *, size_t) = RTMemRealloc >
     474template <class T, void Destruct(T *) = RTMemAutoDestructor<T>, void *Allocator(void *, size_t) = RTMemRealloc >
    426475class RTMemAutoPtr
    427476    : public RTAutoRes<T *, Destruct, RTMemAutoNil<T> >
     
    543592};
    544593
     594
    545595#endif /* __cplusplus */
    546596
Note: See TracChangeset for help on using the changeset viewer.

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