English 中文(简体)
C++树erial化最快的道路
原标题:What s the fastest way to deserialize a tree in C++

I m在C++实施,与一个规模不大的树木结构(Brkhard-Keller-Tree, > 100 MB记忆)合作。 每一 no子的孩子的点子存放在QHash。

每一代母子都拥有孩子,3.1 ...... 和[n] ,孩子的边edge被贴上ed子(x, y[i])的标签,因此用 has子储存 no子是一种明显的解决办法。

class Node {
    int value;
    QHash<int, Node*> children;
    /* ... */
};

我也想将其编成一个档案(目前使用QDataStream)。 这 tree树刚刚建成,然后又发生了变化。

建立树木和使树木脱硫相当缓慢。 I树的装水明显:每一 no子的复耕。 我认为,由于与<条码>新<<<>>>条码>操作者一起创建的许多节点,这是不乐观的。 我读到的有些地方,<代码>新相当缓慢。 最初的建筑并不是一个大问题,因为树 s相当稳定,树 t必须经常重建。 但是,从档案中装上树木应当尽可能快。

实现这一目标的最佳途径是什么?

必须更好地拯救整个树木,把整个树木放在一个有相邻节点的单一记忆区。 那么,为了节省和装上我不得不分配一劳永逸的整块,就将减少空中和空中化。

但是,为了执行这一规定,我必须重新实施QHash,AFAIK。

你们会做些什么来加速帝国化?

感谢你建议作一些总结。 成果如下:

在从档案中重建树木的同时

 1 % of the time is consumed by my own new calls
65 % is consumed by loading the QHash objects (this is implemented by the 
     Qt Library) of each node
12 % is consumed by inserting the nodes into the existing tree
20 % is everything else

因此,这肯定不是我发出造成拖延的新呼吁,而是在每一个节点重建QHash物体。 这主要是:

 QDataStream in(&infile);
 in >> node.hash;

我是否必须挖掘QHash,看一看那里正在发生什么? 我认为,最好的解决办法是,可在没有重建内部数据结构需要的情况下,通过单一读写操作进行序列化。

最佳回答

另一种做法是,在装货时,将你的点数进行序列化并恢复。 我指的是:

<>Serializing:

nodeList = collectAllNodes();

for n in nodelist:
 write ( &n )
 writeNode( n ) //with pointers as-they-are.

<<>Deserializing:

//read all nodes into a list.
while ( ! eof(f))
    read( prevNodeAddress)
    readNode( node )
    fixMap[prevNodeAddress] = &node;
    nodeList.append(node);

//fix pointers to new values.
for n in nodeList:
    for child in n.children:
        child->node = fixMap[child->node]

这样,如果你不插入新的节点,你就可以把病媒分配到一起,并利用这种记忆,减少你们对地图的分配(正如平常说的那样,用清单甚至病媒可能更快)。

问题回答

首先——介绍你的申请,以便你知道需要什么时间——因为你在某个地方读得很慢,或者在树子上 it子是不够的。

这有可能影响国际交易日志的运作——也许你的档案格式不正确/效率低下。

难道你只是有缺陷吗?

或者,在什么地方,你不会忘记造成问题?

衡量在你的案件中究竟需要多少时间,然后处理问题——这节省了很多时间,你避免打断你的设计/编码,在找到真正原因之前确定不存在的业绩问题。

我高度建议boost seriesization Library。 它应与你重新使用的解决办法合作。

序列化/频率绝对最快的办法是像你所说的那样,把连续记忆编成磁盘。 如果你改变树木结构以创造这种环境(可能的话,采用习惯分配惯例),那将非常容易。

不幸的是,我不喜欢QHash,而是从看它就看上去像是哈希姆而不是树。 我是否误解你? 你们是否利用这来绘制重复点图?

我使用了简介(我曾经使用量化数据,现在称为“理性紫外线”),但有许多人())发现你在什么地方使用时间,但我猜测,这要么是多笔记忆拨款,要么是单笔拨款,要么是多读。 为了预先解决上述两个问题(因为你储存了这个问题),你知道需要多少节点,然后撰写/阅读一系列正确长度的节点,每个点子是阵列的索引,而不是记号。

另一种解决办法是利用你自己的记忆分配器,使用连续的记忆空间。 然后,你能够像现在这样丢掉记忆,把记忆重新装上。 该平台具有敏感的平台(即大端/低地终点站,32bit/64bit)。

正如你所说的那样,分配新物体可能很缓慢。 这可以改善对物库的配置,然后使用预先分配的物体,直到该池用尽。 即便如此,你也有可能通过超载有关班级的新/多功能经营人来进行背景工作。

Your own memory allocation with an overloaded operator new() and delete() is a low-cost option (development time). However, this only affects the memory allocation time, and not the Ctor times. Your mileage may vary, but may worth a try.

我只想扩大我的评论:

由于您的描述表明,QHash的序列化需要时间最多,我认为,用QHash替换高List将大大提高民主化速度。

QHash序列化只是主要/价值乳制品的输出,而脱硫则构建一个散射数据结构!

即使你说需要快速的儿童照料,我还是建议你尝试用QList >取代QHash,作为测试。 如果每个节点都有不少儿童(即不到30岁),即使有一位QList,调查也应当足够快。 如果你发现QList不够快,那么你就只能使用(de)serializaton,然后在树木装满后改用 has。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签