michael@0: /* michael@0: ****************************************************************************** michael@0: * michael@0: * Copyright (C) 2002-2012, International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: * michael@0: ****************************************************************************** michael@0: * file name: uobject.h michael@0: * encoding: US-ASCII michael@0: * tab size: 8 (not used) michael@0: * indentation:4 michael@0: * michael@0: * created on: 2002jun26 michael@0: * created by: Markus W. Scherer michael@0: */ michael@0: michael@0: #include "unicode/uobject.h" michael@0: #include "cmemory.h" michael@0: michael@0: U_NAMESPACE_BEGIN michael@0: michael@0: #if U_OVERRIDE_CXX_ALLOCATION michael@0: michael@0: /* michael@0: * Default implementation of UMemory::new/delete michael@0: * using uprv_malloc() and uprv_free(). michael@0: * michael@0: * For testing, this is used together with a list of imported symbols to verify michael@0: * that ICU is not using the global ::new and ::delete operators. michael@0: * michael@0: * These operators can be implemented like this or any other appropriate way michael@0: * when customizing ICU for certain environments. michael@0: * Whenever ICU is customized in binary incompatible ways please be sure michael@0: * to use library name suffixes to distinguish such libraries from michael@0: * the standard build. michael@0: * michael@0: * Instead of just modifying these C++ new/delete operators, it is usually best michael@0: * to modify the uprv_malloc()/uprv_free()/uprv_realloc() functions in cmemory.c. michael@0: * michael@0: * Memory test on Windows/MSVC 6: michael@0: * The global operators new and delete look as follows: michael@0: * 04F 00000000 UNDEF notype () External | ??2@YAPAXI@Z (void * __cdecl operator new(unsigned int)) michael@0: * 03F 00000000 UNDEF notype () External | ??3@YAXPAX@Z (void __cdecl operator delete(void *)) michael@0: * michael@0: * These lines are from output generated by the MSVC 6 tool dumpbin with michael@0: * dumpbin /symbols *.obj michael@0: * michael@0: * ??2@YAPAXI@Z and ??3@YAXPAX@Z are the linker symbols in the .obj michael@0: * files and are imported from msvcrtd.dll (in a debug build). michael@0: * michael@0: * Make sure that with the UMemory operators new and delete defined these two symbols michael@0: * do not appear in the dumpbin /symbols output for the ICU libraries! michael@0: * michael@0: * If such a symbol appears in the output then look in the preceding lines in the output michael@0: * for which file and function calls the global new or delete operator, michael@0: * and replace with uprv_malloc/uprv_free. michael@0: */ michael@0: michael@0: void * U_EXPORT2 UMemory::operator new(size_t size) U_NO_THROW { michael@0: return uprv_malloc(size); michael@0: } michael@0: michael@0: void U_EXPORT2 UMemory::operator delete(void *p) U_NO_THROW { michael@0: if(p!=NULL) { michael@0: uprv_free(p); michael@0: } michael@0: } michael@0: michael@0: void * U_EXPORT2 UMemory::operator new[](size_t size) U_NO_THROW { michael@0: return uprv_malloc(size); michael@0: } michael@0: michael@0: void U_EXPORT2 UMemory::operator delete[](void *p) U_NO_THROW { michael@0: if(p!=NULL) { michael@0: uprv_free(p); michael@0: } michael@0: } michael@0: michael@0: #if U_HAVE_DEBUG_LOCATION_NEW michael@0: void * U_EXPORT2 UMemory::operator new(size_t size, const char* /*file*/, int /*line*/) U_NO_THROW { michael@0: return UMemory::operator new(size); michael@0: } michael@0: michael@0: void U_EXPORT2 UMemory::operator delete(void* p, const char* /*file*/, int /*line*/) U_NO_THROW { michael@0: UMemory::operator delete(p); michael@0: } michael@0: #endif /* U_HAVE_DEBUG_LOCATION_NEW */ michael@0: michael@0: michael@0: #endif michael@0: michael@0: UObject::~UObject() {} michael@0: michael@0: UClassID UObject::getDynamicClassID() const { return NULL; } michael@0: michael@0: U_NAMESPACE_END michael@0: michael@0: U_NAMESPACE_USE michael@0: michael@0: U_CAPI void U_EXPORT2 michael@0: uprv_deleteUObject(void *obj) { michael@0: delete static_cast(obj); michael@0: }