Description
Namespace for custom make_shared implementation.
| Classes | |
| class | class_has_custom_new_operator | 
| Check if a class has a custom new operator.  More... | |
| Functions | |
| template<typename T , typename... Args, typename std::enable_if< class_has_custom_new_operator< T >::value, int >::type = 0> | |
| std::shared_ptr< T > | make_shared (Args &&... args) | 
| Replacement for make_shared guaranteed to use operator newrather thanplacement newin order to avoid memory alignment issues (classes with members that are fixed-sized Eigen matrices have overriden operator new).  More... | |
Function Documentation
◆ make_shared()
template<typename T , typename... Args, typename std::enable_if< class_has_custom_new_operator< T >::value, int >::type  = 0> 
| 
 | inline | 
Replacement for make_shared guaranteed to use operator new rather than placement new in order to avoid memory alignment issues (classes with members that are fixed-sized Eigen matrices have overriden operator new). 
For classes without members that are fixed-sized Eigen matrices (and hence do not have an overriden operator new), it is safe to default to using std::make_shared (no alignment issues).
Dynamic objects of classes with fixed-size vectorizable Eigen object members
- Many of the Chrono classes now have members that are fixed-size vectorizable Eigen types. These classes overload their operator newto generate 16-byte-aligned pointers (using an Eigen - provided macro).
- This requirement for aligned memory allocation has implications on creation of shared pointers. Indeed, std::make_sharedusesplacement newinstead ofoperator new. To address this issue and preserve encapsulation (as much as possible), Chrono provides this formake_shared. This function will automatically infer if it can safely fallback onstd::make_sharedor else create a shared pointer with a mechanism that ensures use of aligned memory. As such, user code should always usechrono_types::make_sharedas inauto my_body = chrono_types::make_shared<ChBody>(); 
