Руслан Урядинский / libuavcan

Dependents:   UAVCAN UAVCAN_Subscriber

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers placement_new.hpp Source File

placement_new.hpp

00001 /*
00002  * Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
00003  */
00004 
00005 #ifndef UAVCAN_UTIL_PLACEMENT_NEW_HPP_INCLUDED
00006 #define UAVCAN_UTIL_PLACEMENT_NEW_HPP_INCLUDED
00007 
00008 #include <cstddef>
00009 #include <uavcan/build_config.hpp>
00010 
00011 /*
00012  * Some embedded C++ implementations don't implement the placement new operator.
00013  * Define UAVCAN_IMPLEMENT_PLACEMENT_NEW to apply this workaround.
00014  */
00015 
00016 #ifndef UAVCAN_IMPLEMENT_PLACEMENT_NEW
00017 # error UAVCAN_IMPLEMENT_PLACEMENT_NEW
00018 #endif
00019 
00020 #if UAVCAN_IMPLEMENT_PLACEMENT_NEW
00021 
00022 inline void* operator new  (std::size_t, void* ptr) throw()
00023 {
00024     return ptr;
00025 }
00026 inline void* operator new[](std::size_t, void* ptr) throw()
00027 {
00028     return ptr;
00029 }
00030 
00031 inline void  operator delete  (void*, void*) throw() { }
00032 inline void  operator delete[](void*, void*) throw() { }
00033 
00034 #else
00035 # include <new>
00036 #endif
00037 
00038 #endif // UAVCAN_UTIL_PLACEMENT_NEW_HPP_INCLUDED