任何加速“新”的方法? [英] Any way to speed up "new"?

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

问题描述




Cracow,28.10.2004


您好,


我有一个程序使用new和new来集中分配和删除相对较小的对象
。运营商。对象

本身由较小的对象组成,再次使用new分配。

从我的测试中我推断出相当一部分计算

花费在内存分配上的时间,这使得程序比使用

纯C编写的等效代码慢得多。函数式编程。问题是:

有没有加速这种内存分配的技术?

(我使用Borland C ++ Builder 4.0 pro,如果它起任何作用)。


此致,


LB


* ------------- -------------------------------------------------- ---- *

| Leslaw Bieniasz博士,|

|波兰科学院物理化学研究所,|
|气体燃料电化学氧化系,|
| UL认证。 Zagrody 13,30-318克拉科夫,波兰。 |

|电话/传真号码:+48(12)266-03-41 |

|电子邮件: nb******@cyf-kr.edu.pl |

* ------------------------------------------- ------------------------ *

|对计算电化学感兴趣? |

|访问我的网站: http://www.cyf-kr.edu。 pl / ~nbbienia |

* -------------------------------- ----------------------------------- *



Cracow, 28.10.2004

Hello,

I have a program that intensively allocates and deletes lots
of relatively small objects, using "new" operator. The objects
themselves are composed of smaller objects, again allocated using "new".
From my tests I deduce that a considerable part of the computational
time is spent on the memory allocation, which makes the program
substantially slower compared to the equivalent code written using
pure "C" functional programming. The question is:
are there any techniques to speed up this memory allocation?
(I use Borland C++ Builder 4.0 pro, if this plays any role).

Sincerely,

L.B.

*-------------------------------------------------------------------*
| Dr. Leslaw Bieniasz, |
| Institute of Physical Chemistry of the Polish Academy of Sciences,|
| Department of Electrochemical Oxidation of Gaseous Fuels, |
| ul. Zagrody 13, 30-318 Cracow, Poland. |
| tel./fax: +48 (12) 266-03-41 |
| E-mail: nb******@cyf-kr.edu.pl |
*-------------------------------------------------------------------*
| Interested in Computational Electrochemistry? |
| Visit my web site: http://www.cyf-kr.edu.pl/~nbbienia |
*-------------------------------------------------------------------*

推荐答案

Leslaw Bieniasz写道:
Leslaw Bieniasz wrote:

克拉科夫,28.10.2004

你好,

我有一个程序集中分配和删除大量相对较小的对象,使用新对象。运营商。对象本身由较小的对象组成,再次使用new分配。
从我的测试中我推断出相当一部分计算时间花费在内存分配上,与使用纯粹的C编写的等效代码相比,使程序显着更慢。函数式编程。问题是:
有没有什么技术可以加速这种内存分配?
(我使用Borland C ++ Builder 4.0 pro,如果它起任何作用)。

Cracow, 28.10.2004

Hello,

I have a program that intensively allocates and deletes lots
of relatively small objects, using "new" operator. The objects
themselves are composed of smaller objects, again allocated using "new".
From my tests I deduce that a considerable part of the computational
time is spent on the memory allocation, which makes the program
substantially slower compared to the equivalent code written using
pure "C" functional programming. The question is:
are there any techniques to speed up this memory allocation?
(I use Borland C++ Builder 4.0 pro, if this plays any role).



首先问题是,你真的需要新吗?所有小的

对象?



First question is, do you really need to "new" all thost small
objects ?




"" Nils O. Sel?sdal"" < NO*@Utel.no>在消息中写道

新闻:KW ****************** @ news4.e.nsc.no ...

""Nils O. Sel?sdal"" <NO*@Utel.no> wrote in message
news:KW******************@news4.e.nsc.no...
Leslaw Bieniasz写道:
Leslaw Bieniasz wrote:

克拉科夫,28.10.2004

您好,

我有一个集中分配和删除批次的程序
相对较小的物体,使用新物体运营商。对象本身由较小的对象组成,再次使用new分配。
从我的测试中我推断出相当一部分计算时间花费在内存分配上,与使用纯粹的C编写的等效代码相比,使程序显着更慢。函数式编程。问题是:
有没有什么技术可以加速这种内存分配?
(我使用Borland C ++ Builder 4.0 pro,如果它起任何作用)。

Cracow, 28.10.2004

Hello,

I have a program that intensively allocates and deletes lots
of relatively small objects, using "new" operator. The objects
themselves are composed of smaller objects, again allocated using "new".
From my tests I deduce that a considerable part of the computational
time is spent on the memory allocation, which makes the program
substantially slower compared to the equivalent code written using
pure "C" functional programming. The question is:
are there any techniques to speed up this memory allocation?
(I use Borland C++ Builder 4.0 pro, if this plays any role).


第一个问题是,你真的需要新吗?所有小的
对象?



First question is, do you really need to "new" all thost small
objects ?




....如果是,请尽量减少使用new的分配数量。我知道

STL中的容器通过预先分配比

所需的更多内存来做到这一点,以防止内存碎片化并最大限度地减少
$ b的数量$ b分配(以及他们所需的时间)。


Catalin



.... and if yes, try to minimize the number of allocations with new. I know
that the containers in STL do this by allocating in advance more memory than
needed, to prevent memory fragmentation and to minimize the number of
allocations (and the time needed for them).

Catalin


Leslaw Bieniasz写道:
Leslaw Bieniasz wrote:

克拉科夫,28.10.2004

你好,

我有一个程序,可以使用和来集中分配和删除大量相对较小的物体。 ;新"运营商。

Cracow, 28.10.2004

Hello,

I have a program that intensively allocates and deletes lots
of relatively small objects, using "new" operator.




索取一份

有效的C ++

Scott Meyers


第10项(如果你编写新的运算符,则写入运算符删除)

讨论了一个解决方案。


< Quote>

让我们退一步,回到基本面。为什么有人想首先编写他们的

自己版本的operator new或operator delete?


通常,答案就是效率。 operator new和

operator delete的默认版本完全适合一般用途,但它们的灵活性

不可避免地为在更受限制的

上下文。对于动态分配大量小型物品的应用程序尤其如此。


....

< /引用>


-

Karl Heinz Buchegger
kb ****** @ gascad.at


这篇关于任何加速“新”的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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