Malloc查询 [英] Malloc Query

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

问题描述

大家好,


许多用户声称由语言

库提供的malloc()和free()导致相当多的

调用相同数量的开销。我们真的可以通过使用

使用定义的函数/用户定义的内存管理器来消除开销。在提供用户定义的malloc()和free()方面是否有任何显着的优势?我想要排除实时系统或内存的嵌入式系统

约束这里。

我说的是通用应用程序。用户定义了内存管理器可以处理内存分配和解除分配的内存分配和解除分配比操作系统更好的方式。 。任何输入/评论

同样值得高度赞赏。


谢谢和问候,

Pushpa

Hi all,

Many users claim that malloc() and free() provided by the language
library results in considerable
amount of overhead in terms of calling the same. Can we really
eliminate overhead by using
used defined functions/user defined memory manager. Is there any
significant advantage in providing user defined malloc() and free(). I
want to exclude realtime systems or embedded systems which are memory
constrained here.
I am talking about general purpose applications. With a user defined
memory manager can it handle
memory allocation and de-allocation in a much better way than what OS
would have done. Any inputs/comments
on the same are highly appreciated.

Thanks and Regards,
Pushpa

推荐答案

pu ********** @ gmail.com 写道:
pu**********@gmail.com writes:

大家好,


许多用户声称malloc()和免费()由语言提供

库导致相当大的间接费用b / b
。我们真的可以通过使用

使用定义的函数/用户定义的内存管理器来消除开销。在提供用户定义的malloc()和free()方面是否有任何显着的优势?我想要排除实时系统或内存的嵌入式系统

约束这里。

我说的是通用应用程序。用户定义了内存管理器可以处理内存分配和解除分配的内存分配和解除分配比操作系统更好的方式。 。
Hi all,

Many users claim that malloc() and free() provided by the language
library results in considerable
amount of overhead in terms of calling the same. Can we really
eliminate overhead by using
used defined functions/user defined memory manager. Is there any
significant advantage in providing user defined malloc() and free(). I
want to exclude realtime systems or embedded systems which are memory
constrained here.
I am talking about general purpose applications. With a user defined
memory manager can it handle
memory allocation and de-allocation in a much better way than what OS
would have done.



当然,原则上你可以编写一个比你的系统提供的更好的malloc()

。但是,系统的标准作者
库的作者(希望如此)投入了大量的精力和精力来编写一个好的

通用分配器,所以你可能会很难做得更好。


现在,短语通用给出一个警告。在编写分配器时需要考虑很多因素:速度,效率

内存使用情况,面对用户错误时的鲁棒性,避免使用

碎片,将内存返回给操作系统等。这些涉及

权衡。你的图书馆的malloc()会在这些之间选择一些余额

,并且你可能想要一个不同的余额,在

你自己的情况下实施可以做得更好。另一个因素是

,如果你知道如何使用你的分配器

(例如,你将主要分配73字节的块,很少释放
他们),你可以适当地优化,系统的malloc()不能



我'如果你正在考虑这个问题,首先要看一些

许多可用的内存分配器实现。其中一些

非常先进。然后,一旦你有几个可能的b
候选人,对他们进行基准测试,看看哪个最适合你的

申请。

Certainly in principle you could write a better malloc() than the one
your system provides. However, the authors of your system''s standard
library (hopefully) put a lot of thought and effort into writing a good
general-purpose allocator, so you might have a hard time doing better.

Now, the phrase "general-purpose" gives a caveat. There are a lot of
possible factors to consider in writing an allocator: speed, efficient
usage of memory, robustness in the face of user error, avoiding
fragmentation, returning memory to the OS, etc. These involve
tradeoffs. Your library''s malloc() will have chosen some balance
between these, and it''s possible that you want a different balance, in
which case your own implementation could do "better". Another factor is
that if you know something about how you are going to use your allocator
(e.g. you will be mainly allocating 73-byte chunks and rarely freeing
them), you can optimize appropriately, which the system''s malloc() can''t
do.

I''d suggest if you are considering this, to first look at some of the
many freely available memory allocator implementations out there. Some
of them are quite advanced. Then, once you have a few possible
candidates, benchmark them and see which is the best for your
application.


pu**********@gmail.com 写道:

大家好,


许多用户声称malloc()和free()由语言提供

库在调用相同数量时会产生相当大的开销。我们真的可以通过使用

使用定义的函数/用户定义的内存管理器来消除开销。
Hi all,

Many users claim that malloc() and free() provided by the language
library results in considerable
amount of overhead in terms of calling the same. Can we really
eliminate overhead by using
used defined functions/user defined memory manager.



您需要了解malloc()和free()的开销是他们所做的工作的内在后果。需要执行。

你会发现创建一个比标准提供的更快版本的malloc()更难,但不一定是不可能的图书馆。


唯一可以合理地希望获得更快内存的方法

经理比malloc()/ free()更有限的定义它

功能比malloc()/ free()。例如:内存管理器

总是返回完全相同大小的分配,可以比malloc()明显快得多。从来没有实际需要释放内存的内存管理器也可以明显更快。

You need to understand that the overhead of malloc() and free() is an
intrinsic consequence of the job that they''re required to perform.
You''ll find it difficult, though not necessarily impossible, to create a
faster version of malloc() than the one provided by the standard library.

The only way you can reasonably hope for a significantly faster memory
manager than malloc()/free() is to define it with more limited
capabilities than malloc()/free(). For example example: a memory manager
that always returns allocations of exactly the same size can be
significantly faster than malloc(). A memory manager that never actually
needs to release memory can also be significantly faster.


pu ********** @ gmail.com 写道:

大家好,


许多用户声称由语言

库提供的malloc()和free()结果相当可观
调用相同的开销量。
Hi all,

Many users claim that malloc() and free() provided by the language
library results in considerable
amount of overhead in terms of calling the same.



许多用户声称各种愚蠢。引用的索赔

这里没有有用的内容,因此没有真正的争议;

只能通过选择合适或不合适的
上下文来证明或证明。这就像是说直升机效率低。没有

描述手头的任务。

"Many users" claim all manner of foolishness. The claim quoted
here is empty of useful content and hence not really debatable; it
can be proven or disproven merely by choosing suitable or unsuitable
contexts. It''s like saying "helicopters are inefficient" without
describing the task at hand.


我们真的可以

通过使用
来消除开销
使用定义的函数/用户定义的内存管理器。在提供用户定义的malloc()和free()方面是否有任何显着的优势?我想要排除实时系统或内存的嵌入式系统

约束这里。

我说的是通用应用程序。用户定义了内存管理器可以处理内存分配和解除分配的内存分配和解除分配比操作系统更好的方式。 。任何输入/评论

同样值得高度赞赏。
Can we really
eliminate overhead by using
used defined functions/user defined memory manager. Is there any
significant advantage in providing user defined malloc() and free(). I
want to exclude realtime systems or embedded systems which are memory
constrained here.
I am talking about general purpose applications. With a user defined
memory manager can it handle
memory allocation and de-allocation in a much better way than what OS
would have done. Any inputs/comments
on the same are highly appreciated.



如果你比系统提供的内存管理员更聪明,那么你可能比能够做出巨大的改善。您还可以利用

库编写者所缺乏的特定于应用程序的知识,在特定的

应用程序中实现巨大的改进。但是如果你正在写一个通用的b $ b内存管理器并且你只比实现者稍微聪明一点,那么你可能只会做一点点b $ b好一点。如果那样的话。


根据我的经验,大的收益不是来自取代malloc()

和朋友,而是来自于建立更丰富的API' (或其他

低级别内存管理器)。考虑一下:malloc()只获取一个

的信息,即请求的字节数。如果malloc()知道分配是短暂的还是长期存在,那么malloc()可以做更好的工作吗?知道有些分配是与其他人相关的,有相似的生命周期并且几乎同时在

下访问,这可能会从中获益吗?知道哪些分配将保持不变大小并且可能重新分配哪些分配是否有用?

我敢肯定你能想到内存管理员可能的方式生产效率

使用这种性质的信息,信息malloc()没有。


但是,这种信息往往有点应用 -

具体,这使我们远离通用目的目标。如果你是
计划使用malloc()等的窄API。并且你在各种不同的应用程序中测量了

的性能,你不会以很大的差距击败系统提供的经理。


-
Er ******** *@sun.com


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

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