id summary reporter owner description type status milestone component version severity resolution keywords cc 2520 Overloaded new operator are not called from serialization Runar Undheim Robert Ramey "Could someone help to update the serialization code in boost to call the overloaded new operator, please? There already exist some code, but the code is not active because of a #if 0 statement. And if I set the code to #if 1 the code is not compiling with Visual C++ 2005. So I have updated the heap_allocator implementation in archive\detail\iserializer.hpp to support overload of new operator, but I'm not sure if it will work on all compilers. I have just tested the code with Visual C++ 2005. First the code that I used to check if the new operator is overloaded. If there are compilers that don't support the code, the implementation could be updated using defines and only return false. This way we take advantage of the information on supported compilers, an the code will work as before on unsupported compilers. Should the code that check if it has a new operator be part of the Type Traits library? {{{ typedef char True; // sizeof(True) == 1 typedef struct { char a[2]; } False; // sizeof(False) > 1 template struct test; template const True *hasNewOperator(C*, test* = NULL) { // Function must be implemented on // Visual C++ 2005 to prevent linking error return NULL; } template const False *hasNewOperator(...) { // Function must be implemented on // Visual C++ 2005 to prevent linking error return NULL; } /* #define hasNewOperator(f) (sizeof(*hasNewOperator (static_cast(NULL))) == sizeof(True)) */ }}} The heap_allocator is then updated to use the hasNewOperator: {{{ template struct heap_allocator { template static T* new_operator(U); static T* new_operator(const True*) { return static_cast((T::operator new)(sizeof(T))); } static T* new_operator(const False*) { return static_cast(operator new(sizeof(T))); } static T * invoke() { return new_operator(hasNewOperator( static_cast(NULL))); } }; }}}" Feature Requests closed Boost 1.38.0 serialization Boost 1.37.0 Problem fixed overloading new operator