VirtualBox

Changeset 34784 in vbox


Ignore:
Timestamp:
Dec 7, 2010 2:48:13 PM (14 years ago)
Author:
vboxsync
Message:

iprt/mem.h: Added RTMEMEF_NEW_AND_DELETE_OPERATORS, triggered by RTMEM_WRAP_SOME_NEW_AND_DELETE_TO_EF.

File:
1 edited

Legend:

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

    r33540 r34784  
    686686 */
    687687RTDECL(void *) RTMemEfDupEx(const void *pvSrc, size_t cbSrc, size_t cbExtra, const char *pszTag, RT_SRC_POS_DECL) RT_NO_THROW;
     688
     689/** @def RTMEM_WRAP_SOME_NEW_AND_DELETE_TO_EF
     690 * Define RTMEM_WRAP_SOME_NEW_AND_DELETE_TO_EF to enable electric fence new and
     691 * delete operators for classes which uses the RTMEMEF_NEW_AND_DELETE_OPERATORS
     692 * macro.
     693 */
     694/** @def RTMEMEF_NEW_AND_DELETE_OPERATORS
     695 * Defines the electric fence new and delete operators for a class when
     696 * RTMEM_WRAP_SOME_NEW_AND_DELETE_TO_EF is define.
     697 */
     698#if defined(RTMEM_WRAP_SOME_NEW_AND_DELETE_TO_EF) && !defined(RTMEM_NO_WRAP_SOME_NEW_AND_DELETE_TO_EF)
     699# if defined(RT_EXCEPTIONS_ENABLED)
     700#  define RTMEMEF_NEW_AND_DELETE_OPERATORS() \
     701        void *operator new(size_t cb) throw(std::bad_alloc) \
     702        { \
     703            void *pv = RTMemEfAlloc(cb, RTMEM_TAG, RT_SRC_POS); \
     704            if (RT_UNLIKELY(!pv)) \
     705                throw std::bad_alloc(); \
     706            return pv; \
     707        } \
     708        void *operator new(size_t cb, const std::nothrow_t &nothrow_constant) throw() \
     709        { \
     710            NOREF(nothrow_constant); \
     711            return RTMemEfAlloc(cb, RTMEM_TAG, RT_SRC_POS); \
     712        } \
     713        void *operator new[](size_t cb) throw(std::bad_alloc) \
     714        { \
     715            void *pv = RTMemEfAlloc(cb, RTMEM_TAG, RT_SRC_POS); \
     716            if (RT_UNLIKELY(!pv)) \
     717                throw std::bad_alloc(); \
     718            return pv; \
     719        } \
     720        void *operator new[](size_t cb, const std::nothrow_t &nothrow_constant) throw() \
     721        { \
     722            NOREF(nothrow_constant); \
     723            return RTMemEfAlloc(cb, RTMEM_TAG, RT_SRC_POS); \
     724        } \
     725        \
     726        void operator delete(void *pv) throw() \
     727        { \
     728            RTMemEfFree(pv, RT_SRC_POS); \
     729        } \
     730        void operator delete(void *pv, const std::nothrow_t &nothrow_constant) throw() \
     731        { \
     732            NOREF(nothrow_constant); \
     733            RTMemEfFree(pv, RT_SRC_POS); \
     734        } \
     735        void operator delete[](void *pv) throw() \
     736        { \
     737            RTMemEfFree(pv, RT_SRC_POS); \
     738        } \
     739        void operator delete[](void *pv, const std::nothrow_t &nothrow_constant) throw() \
     740        { \
     741            NOREF(nothrow_constant); \
     742            RTMemEfFree(pv, RT_SRC_POS); \
     743        } \
     744        \
     745        typedef int UsingElectricNewAndDeleteOperators
     746# else
     747#  define RTMEMEF_NEW_AND_DELETE_OPERATORS() \
     748        void *operator new(size_t cb) \
     749        { \
     750            return RTMemEfAlloc(cb, RTMEM_TAG, RT_SRC_POS); \
     751        } \
     752        void *operator new(size_t cb, const std::nothrow_t &nothrow_constant) \
     753        { \
     754            NOREF(nothrow_constant); \
     755            return RTMemEfAlloc(cb, RTMEM_TAG, RT_SRC_POS); \
     756        } \
     757        void *operator new[](size_t cb) \
     758        { \
     759            return RTMemEfAlloc(cb, RTMEM_TAG, RT_SRC_POS); \
     760        } \
     761        void *operator new[](size_t cb, const std::nothrow_t &nothrow_constant) \
     762        { \
     763            NOREF(nothrow_constant); \
     764            return RTMemEfAlloc(cb, RTMEM_TAG, RT_SRC_POS); \
     765        } \
     766        \
     767        void operator delete(void *pv) \
     768        { \
     769            RTMemEfFree(pv, RT_SRC_POS); \
     770        } \
     771        void operator delete(void *pv, const std::nothrow_t &nothrow_constant) \
     772        { \
     773            NOREF(nothrow_constant); \
     774            RTMemEfFree(pv, RT_SRC_POS); \
     775        } \
     776        void operator delete[](void *pv) \
     777        { \
     778            RTMemEfFree(pv, RT_SRC_POS); \
     779        } \
     780        void operator delete[](void *pv, const std::nothrow_t &nothrow_constant) \
     781        { \
     782            NOREF(nothrow_constant); \
     783            RTMemEfFree(pv, RT_SRC_POS); \
     784        } \
     785        \
     786        typedef int UsingElectricNewAndDeleteOperators
     787# endif
     788#else
     789# define RTMEMEF_NEW_AND_DELETE_OPERATORS() \
     790        typedef int UsingDefaultNewAndDeleteOperators
     791#endif
     792#ifdef DOXYGEN_RUNNING
     793# define RTMEM_WRAP_SOME_NEW_AND_DELETE_TO_EF
     794#endif
    688795
    689796/** @def RTMEM_WRAP_TO_EF_APIS
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