malloc()的缺点 [英] Disadvantages of malloc()

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

问题描述

在一些小内存系统上,malloc()是否属实?

不支持C库吗?

为什么在这样的系统上避免动态内存分配?什么是

这里使用malloc()的主要问题是什么?


谢谢!

On some small-memory systems, is it true that "malloc()" is not supported by
the C library?

Why is ''dynamic memory allocation'' so avoided on such systems? What are
major problems of using malloc() here?

Thanks!

推荐答案

Aire写道:
Aire wrote:
在一些小内存系统上,
malloc()是否属实? C库不支持?

为什么在这样的系统上避免动态内存分配?
在这里使用malloc()的主要问题是什么?
On some small-memory systems,
Is it true that "malloc()" is not supported by the C library?

Why is ''dynamic memory allocation'' so avoided on such systems?
What are major problems of using malloc() here?




comp.lang.c新闻组

是获取任何特定架构*建议的好地方。


请尝试使用comp.arch.embedded新闻组。



The comp.lang.c newsgroup
is a good place to get *bad* advice about any particular architecture.

Try the comp.arch.embedded newsgroup instead.


在文章< k8 ************ *****【@@@@@@@@@@@@@@@@写道:
In article <k8*********************@bgtnsc05-news.ops.worldnet.att.net>,
Aire <ai*****@zoomit.org> wrote:
在一些小内存系统上,malloc()是否属实?
C库不支持?


所有声称支持托管C实现的系统都需要

来支持malloc。[1]


目前,大多数小内存系统都是独立实现,实现大部分标准库不需要
; malloc

是标准库的一部分的流行候选者。


为什么在这样的系统上避免动态内存分配? ?这里使用malloc()的主要问题是什么?
On some small-memory systems, is it true that "malloc()" is not supported by
the C library?
All systems claiming to support a hosted C implementation are required
to support malloc.[1]

These days most small-memory systems are freestanding implementations,
which are not required to implement most of the standard library; malloc
is a popular candidate for a part of the standard library to leave out.

Why is ''dynamic memory allocation'' so avoided on such systems? What are
major problems of using malloc() here?




通常因为动态内存分配是不必要的并且使得

可能在有限的环境中难以解决的一些问题。


这里的许多常客已经在有限的环境中使用独立实施

能够告诉你超过

你想知道我正在挥手的细节。

comp.arch.embedded(讨论嵌入式系统,其中最独立的

使用C实现)也可能会对这个主题有所了解。

dave


[1]好吧,至少如果他们想让人们相信这个主张。


-

Dave Vandervies dj ****** @ csclub.uwaterloo.ca

从你的英语课开始;只有当你已经明白拼写

不是完全可选的时候你才准备进入更严格的编程规则。 --Richard Bos in comp.lang.c



Usually because dynamic memory allocation isn''t necessary and makes
possible some problems that are hard to solve in limited environments.

A lot of the regulars here have worked with freestanding implementations
in limited environments and will be able to tell you more than
you ever wanted to know about the details I''m waving my hands over.
comp.arch.embedded (discussing embedded systems, where most freestanding
C implementations are used) might also be able to shed some light on
the subject.
dave

[1] Well, at least if they want people to believe the claim.

--
Dave Vandervies dj******@csclub.uwaterloo.ca
Start with your English classes; only when you''ve got the point that spelling
is not completely optional are you ready to proceed to the rather more exacting
discipline of programming. --Richard Bos in comp.lang.c




" Aire" < AI ***** @ zoomit.org>在消息新闻中写道:

"Aire" <ai*****@zoomit.org> wrote in message news:

在一些小内存系统上,malloc()是否属实?是不是C库支持?

是的,一些不那么小的系统,比如游戏机也不支持它。
为什么''动态内存分配在这样的系统上如此避免?
在这里使用malloc()的主要问题是什么?

On some small-memory systems, is it true that "malloc()" is not
supported by the C library?
Yes, some not-so small systems like games consoles don''t support it either.
Why is ''dynamic memory allocation'' so avoided on such systems?
What are major problems of using malloc() here?



只要你能声明一个合理大小的全局数组就很容易了to

实现malloc()(称之为mymalloc())。

有很多理由不提供malloc(),但主要是为了

程序员可以完全控制分配的每个字节。例如我写的一个
游戏使用了大量相同大小的小分配,所以我自定义了内存分配器以有效地提供这些。使用

内置的malloc(),这是不可能的。


As long as you can declare a global array of reasonable size it is easy to
implement malloc() (call it mymalloc()).
There are lots of reasons for not providing malloc(), but mainly so that the
programmer has complete control over every byte allocated. For instance one
game I wrote used a lot of small allocations of the same size, so I
customised the memory allocator to provide these efficiently. using a
built-in malloc() this would not have been posible.


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

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