在最短的时间内释放记忆 [英] freeing memory in shortest time

查看:81
本文介绍了在最短的时间内释放记忆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


我有一个指向主结构的指针,它又包含了

结构,枚举,char,int,float和复杂的结构。


当我释放主结构的所有内容时,它花了我很多时间(因为我必须循环确定数据类型和释放

吧)。有没有想法在

最短的时间内释放结构的所有内容。

Hello,

I have a pointer to a main structure which again consists of
structures, enums, char, int, float and again complex structures.

When i free all the contents of the main structure, it takes me a lot
of time (since i have to loop determining the data type and freeing
it). Is there any idea to free all the contents of the structure in
shortest possible time.

推荐答案

或者我应该切换到静态内存而不是???在那种情况下

应该小心谨慎。


Pl建议
Or probably should i switch to static memory instead??? In that case
what care should be taken.

Pl advice


vivek写道:
vivek wrote:

你好,


我有一个指向主结构的指针,它又包含了

结构,enums,char,int,float和复杂的结构。


当我释放主结构的所有内容时,它需要我很多

of时间(因为我必须循环确定数据类型并释放

)。有没有想法在最短的时间内释放结构中的所有内容。
Hello,

I have a pointer to a main structure which again consists of
structures, enums, char, int, float and again complex structures.

When i free all the contents of the main structure, it takes me a lot
of time (since i have to loop determining the data type and freeing
it). Is there any idea to free all the contents of the structure in
shortest possible time.



您可以尝试将结构设为静态。或者你可以尝试使用每个结构的动态内存指针的单独缓存

元素。这将消耗额外的内存,但将消除

需要遍历结构以释放它的所有组件。


无论如何,我怀疑遍历这个结构将是你最严重的瓶颈,特别是如果你一次性完成所有这些。

You might try making the structure static. Or you might try having a
separate cache of all the pointers to dynamic memory for each structure
element. This will consume additional memory, but will eliminate the
need to traverse the structure to free all it''s components.

In anycase, I doubt that traversing the structure is going to be your
most serious bottleneck, particularly if you do it all at once.


vivek说:
vivek said:

你好,


我有一个指向主要结构的指针,它还包含

结构,枚举,char,int,float和复杂的结构。


当我释放主结构的所有内容时,它需要我很多

时间(因为我必须循环确定数据类型并释放

)。有没有想法在最短的时间内释放结构中的所有内容。
Hello,

I have a pointer to a main structure which again consists of
structures, enums, char, int, float and again complex structures.

When i free all the contents of the main structure, it takes me a lot
of time (since i have to loop determining the data type and freeing
it). Is there any idea to free all the contents of the structure in
shortest possible time.



好​​吧,退出(0)就可以了。但是我很想知道你为什么认为它花了很多时间才花了很多钱。如今计算机速度非常快。这真的是你的程序的

瓶颈吗?分析告诉你什么?


-

Richard Heathfield< http://www.cpax.org.uk>

电子邮件:-http:// www。 + rjh @

谷歌用户:< http://www.cpax.org.uk/prg/writings/googly.php>

Usenet是一个奇怪的放置" - dmr 1999年7月29日

Well, exit(0) will do it. But I''m curious to know why you think it''s taking
a lot of time. Computers are pretty fast nowadays. Is this really the
bottleneck for your program? What did profiling tell you?

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999


这篇关于在最短的时间内释放记忆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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