模板类的升压系列化设置跟踪特征,以减少内存消耗 [英] Set tracking traits of template class in boost serialization to reduce memory consumption

查看:183
本文介绍了模板类的升压系列化设置跟踪特征,以减少内存消耗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于这链接说用于定义模板类的特征,我们应该手动定义它,或者我们从特征提取类我们班。但我想自动进行这个过程,这个理由从 BOOST_CLASS_TRACKING 启发我写的一击code:

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:

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>)

我用这个宏在我的code,但现在我不知道是否该宏prevent从跟踪或不类。
我有一个大的数据结构,我想序列化过程中消耗更少的内存。通过检查我的节目 callgrind 我发现,在系列化lib中最新()调用的是命名函数 save_pointer 文件 basic_oarchive.hpp 存储地图的指针来跟踪对象,我希望通过改变所有类 never_track 内存消耗显著减少。但是,没有显著变化发生了。

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?

编辑:

我简要的项目是一个线索,每个节点是一个抽象类的指针和指向有其子。如果我不关闭指针跟踪所有这些节点序列化过程中的地图升压序列化库和内存成倍的节省上两个。

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.

更新:

我把这里的微距效果很好。但是,对于禁用跟踪您必须注意到有该库跟踪他们许多内部指针。例如,在我的情况下,有很多指向对&LT;常量键,值&GT; 这是许多STL或其它容器的内部指针。通过禁用所有的内存消耗显著减少。

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.

推荐答案

OP从此张贴的合成基准,它表明他正试图衡量的东西。

UPDATE

OP has since posted the synthetic benchmark that does show the thing he is trying to measure.

我跑了地块下,两次:左边只是建立一个大的树,并在右侧还其序列:的 https://gist.github.com/sehe/5f060a3daccfdff3178c#file-sbs-txt

I ran it under Massif, twice: on the left just building a large Tree, and on the right also serializing it: https://gist.github.com/sehe/5f060a3daccfdff3178c#file-sbs-txt

在这里输入的形象描述

请注意内存的使用情况如何,基本上完全相同:目标跟踪是不是一个问题,在这里

Note how memory usage is basically exactly identical: object tracking is not an issue here

为了比较,当启用跟踪: https://gist.github.com/8d3e5dba7b124a750b9b

For comparison, when tracking is enabled: https://gist.github.com/8d3e5dba7b124a750b9b

在这里输入的形象描述

问: 我在code使用这个宏,但现在我不知道是否该宏prevent类从跟踪与否。

是的。显然不行。

从旧的答案原文脚注:

¹否它通常不会是存储器双倍数量 - 这将需要一个很特定类型的数据具有非常低的有效载荷到线索节点大小比设置的

¹ No it would not usually be double the amount of memory - that would take a very specific kind of data set with a very low payload-to-trie-node size ratio

这篇关于模板类的升压系列化设置跟踪特征,以减少内存消耗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆