As this link stated for defining traits for a template class we should define it manually or we extract our class from the trait class. But I want to make this process automatically, for this reason inspired from BOOST_CLASS_TRACKING
I wrote the blow code:
#include<boost/preprocessor/tuple/enum.hpp>
...
#define FOO_CLASS_TRACKING(E, PARAMETER_TUPLE, ...) \
namespace boost { \
namespace serialization { \
template<BOOST_PP_TUPLE_ENUM(PARAMETER_TUPLE)> \
struct tracking_level< __VA_ARGS__ > \
{ \
typedef mpl::integral_c_tag tag; \
typedef mpl::int_< E> type; \
BOOST_STATIC_CONSTANT( \
int, \
value = tracking_level::type::value \
); \
/* tracking for a class */ \
BOOST_STATIC_ASSERT(( \
mpl::greater< \
/* that is a prmitive */ \
implementation_level< __VA_ARGS__ >, \
mpl::int_<primitive_type> \
>::value \
)); \
}; \
}}
// which used like this
FOO_CLASS_TRACKING(boost::serialization::track_never, (typename Key, typename Value), Foo<Key, Value>)
I used this macro in my code, but now I am not sure whether this macro prevent the class from tracking or not.
I have a big data structure and I want to consume less memory during serialization. By checking my program using callgrind
I found that most of new()
call in serialization lib is from a function named save_pointer
in file basic_oarchive.hpp
which stores a map of pointers to track objects, I expected by changing all classes to never_track
memory consumption reduces significantly. But no significant change was happened.
Does my macro have a problem? or memory consumption of serialization does not relate to tracking of objects? Is there any way to find that tracking traits of a class was set or not?
Edit:
My project in brief is a trie that each node is a pointer of an abstract class and has pointer to its children. If I do not disable tracking of pointers all these nodes save on a map of boost serialization library and memory multiplies by two during serialization.
Update:
The macro I put here works well. But for disabling tracking you must notice that there are many internal pointer that the library tracks them. For example in my case there was many pointer to pair<const Key, Value>
which is the internal pointer of many stl or other containers. By disabling all of them memory consumption reduces significantly.