池问题 [英] Pool question

查看:51
本文介绍了池问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个大型图形对象,每当我需要它们时我就会添加节点,并且我会分别通过新节点创建它们。我知道这个如果我要单独分配数千个节点,那么
很慢。我想要通过池中的分配来替换这个分配。我能想到的一个简单的方法是手动分配一个大型数组节点(因为我估计会有多少节点),所以/>
并使用指向数组元素的指针,然后当然跟踪

使用的节点。我想我可以很容易地做到这一点,因为在我目前的版本中

没有释放节点(直到最后,当所有内容都被释放时),所以它是可管理的写一个复杂的游泳池

机制。但是可能这种简单的方法将是不足够的。此外,我正试图从另一种语言转换到C ++,所以我想知道它是如何用C ++风格完成的。所以我想b / b
想知道图书馆里是否有一些游泳池设施。我已经看到有一个Boost池库,但我不知道它是否是最简单的选择。

解决方案

a_linux_user写道:


我正在创建一个大型图形对象,每当我使用$ b时我都会添加节点$ b需要它们,我分别通过新节点创建它们。我知道这个如果我要单独分配数千个节点,那么
很慢。我想要通过池中的分配来替换这个分配。我能想到的一个简单的方法是手动分配一个大型数组节点(因为我估计会有多少节点),所以/>
并使用指向数组元素的指针,然后当然跟踪

使用的节点。我想我可以很容易地做到这一点,因为在我目前的版本中

没有释放节点(直到最后,当所有内容都被释放时),所以它是可管理的写一个复杂的游泳池

机制。但是可能这种简单的方法将是不足够的。此外,我正试图从另一种语言转换到C ++,所以我想知道它是如何用C ++风格完成的。所以我想b / b
想知道图书馆里是否有一些游泳池设施。我已经看到有一个Boost池库,但我不知道它是否是最简单的选择




首先,我会更改代码,以便使用分配器而不是使用

new并直接删除。您可以使用标准的

分配器来测试代码。


然后我会用池分配器替换该分配器。您可以查看

各种替代方案,也可以自己编写。最后,你可以选择最快的


最好


Kai-Uwe Bux


" a_linux_user" < bd ****** @ gmail.comwrote:


>

我正在创建一个大图形对象,其中我每当我
需要它们时添加节点,我分别通过''new node''创建它们。我知道这个如果我要单独分配数千个节点,那么
很慢。我想要通过池中的分配来替换这个分配。我能想到的一个简单的方法是手动分配一个大型数组节点(因为我估计会有多少节点),所以/>
并使用指向数组元素的指针,然后当然跟踪

使用的节点。我想我可以很容易地做到这一点,因为在我目前的版本中

没有释放节点(直到最后,当所有内容都被释放时),所以它是可管理的写一个复杂的游泳池

机制。但是可能这种简单的方法将是不足够的。此外,我正试图从另一种语言转换到C ++,所以我想知道它是如何用C ++风格完成的。所以我想b / b
想知道图书馆里是否有一些游泳池设施。我已经看到有一个Boost池库,但我不知道它是否是最简单的选择




寻找operator new()在您的C ++手册和网络上。

通过这种机制,您可以拥有自己的分配器。


a_linux_user写道:


我正在创建一个大型图形对象,每当我需要它时我都会添加节点,并且我通过''创建它们新节点''单独。我知道这个如果我要单独分配数千个节点,那么
很慢。我想要通过池中的分配来替换这个分配。



如果所有节点都有相同的大小,你可以使用它:

http://warp.povusers.org/FSBAllocator/


I am creating a large graph object in which I add nodes whenever I
need them, and I create them by ''new node'' individually. I know this
is slow if I am going to allocate thousands of nodes individually. I
want to replace this allocation by an allocation from a pool. One
simple method I can think of is a manual allocation of a large array
of nodes (since I have an estimate of how many nodes there will be),
and use pointers to array elements, and then of course keep track of
used nodes. I think I can do this easily because in my current version
there is no freeing of nodes (until the end, when everything is
freed), so it is manageable without writing a complicated pool
mechanism. But potentially such a simplistic method will be
inadequate. Moreover I am trying to make a transition to C++ from
another language, so I want to know how it is done in C++ style. So I
would like to know if there is some pool facility in the library. I
have seen that there is a Boost pool library but I don''t know if it is
the simplest choice.

解决方案

a_linux_user wrote:

I am creating a large graph object in which I add nodes whenever I
need them, and I create them by ''new node'' individually. I know this
is slow if I am going to allocate thousands of nodes individually. I
want to replace this allocation by an allocation from a pool. One
simple method I can think of is a manual allocation of a large array
of nodes (since I have an estimate of how many nodes there will be),
and use pointers to array elements, and then of course keep track of
used nodes. I think I can do this easily because in my current version
there is no freeing of nodes (until the end, when everything is
freed), so it is manageable without writing a complicated pool
mechanism. But potentially such a simplistic method will be
inadequate. Moreover I am trying to make a transition to C++ from
another language, so I want to know how it is done in C++ style. So I
would like to know if there is some pool facility in the library. I
have seen that there is a Boost pool library but I don''t know if it is
the simplest choice.

First, I would change the code so that is uses an allocator instead of using
new and delete directly. You can test the code using the standard
allocator.

Then I would replace that allocator with a pool allocator. You can check out
various alternatives and also write your own. In the end, you can choose
the fastest.
Best

Kai-Uwe Bux


"a_linux_user" <bd******@gmail.comwrote:

>
I am creating a large graph object in which I add nodes whenever I
need them, and I create them by ''new node'' individually. I know this
is slow if I am going to allocate thousands of nodes individually. I
want to replace this allocation by an allocation from a pool. One
simple method I can think of is a manual allocation of a large array
of nodes (since I have an estimate of how many nodes there will be),
and use pointers to array elements, and then of course keep track of
used nodes. I think I can do this easily because in my current version
there is no freeing of nodes (until the end, when everything is
freed), so it is manageable without writing a complicated pool
mechanism. But potentially such a simplistic method will be
inadequate. Moreover I am trying to make a transition to C++ from
another language, so I want to know how it is done in C++ style. So I
would like to know if there is some pool facility in the library. I
have seen that there is a Boost pool library but I don''t know if it is
the simplest choice.

Look for "operator new()" in your C++ manual(s) and on the net.
By this mechanism you can have your own allocator.


a_linux_user wrote:

I am creating a large graph object in which I add nodes whenever I
need them, and I create them by ''new node'' individually. I know this
is slow if I am going to allocate thousands of nodes individually. I
want to replace this allocation by an allocation from a pool.

If all the nodes have the same size, you can use this:

http://warp.povusers.org/FSBAllocator/


这篇关于池问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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