远点 [英] far pointers

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

问题描述

任何人都可以解释什么是远指针和malloc和calloc之间有什么区别

。哪个更好?

Can any one explain what are far pointers and what is the difference
between malloc and calloc .Which is better ?

推荐答案

Harsimran< sa ************ @ yahoo.co.in>潦草地写了下面的内容:
Harsimran <sa************@yahoo.co.in> scribbled the following:
任何人都可以解释什么是远指针以及malloc和calloc之间有什么区别。哪个更好?
Can any one explain what are far pointers and what is the difference
between malloc and calloc .Which is better ?




远端指针不是ISO标准C概念,因此是非主题的

。 malloc和calloc之间有两个区别:

1)malloc除了一个参数,calloc除了两个。 calloc分配的大小是参数相乘的参数。

2)calloc自动将分配的内存归零,malloc不会。


-

/ - Joona Palaste(pa*****@cc.helsinki.fi)-------------芬兰----- --- \

\ - http:// www.helsinki.fi/~palaste ---------------------规则! -------- /

我们怎样才能用性来获得我们想要的东西?性是我们想要的。

- Frasier Crane博士



Far pointers are not an ISO standard C concept and are thus off-topic
here. There are two differences between malloc and calloc:
1) malloc excepts one parameter, calloc excepts two. The size that
calloc allocates is the parameters multiplied together.
2) calloc automatically zeroes the allocated memory, malloc does not.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"How can we possibly use sex to get what we want? Sex IS what we want."
- Dr. Frasier Crane


在文章< news:b8 ******* *******************@posting.google。 com>

Harsimran< sa ************ @ yahoo.co.in>写道:
In article <news:b8**************************@posting.google. com>
Harsimran <sa************@yahoo.co.in> wrote:
任何人都可以解释什么是远指针...


没有这样的东西。 (参见comp.lang.c FAQ,问题19.40d。)

和malloc和calloc有什么区别。哪个更好?
Can any one explain what are far pointers ...
There are no such things. (See the comp.lang.c FAQ, question 19.40d.)
and what is the difference between malloc and calloc .Which is better ?




哪个更好,巧克力或草莓;椰子酱油;

a锤子还是扳手?


调用malloc(n)形式返回NULL(失败)或

指向n个连续字节中的第一个的连接。调用形式

calloc(nitems,size)返回NULL(失败)或指针

到第一个nitems * size连续字节,同时调用

memset()将所有这些字节设置为''\0''。


如果需要预先设置为''\0'的字节'你可以使用calloc();如果你只需要
需要字节,请使用malloc()。

-

In-Real-Life:克里斯托雷克,风河系统

美国犹他州盐湖城(40°39.22''N,111°50.29''W)+1 801 277 2603

电子邮件:忘了它 http://web.torek.net/torek/index.html

由于垃圾邮件发送者,阅读电子邮件就像在垃圾中搜索食物一样。



Which is better, chocolate or strawberry; coconut or soy sauce;
a hammer or a wrench?

A call of the form malloc(n) returns either NULL (failure) or a
pointer to the first of n contiguous bytes. A call of the form
calloc(nitems, size) returns either NULL (failure) or a pointer
to the first of nitems*size contiguous bytes, after also calling
memset() to set all those bytes to ''\0''.

If you need bytes pre-set to ''\0'' you can use calloc(); if you just
need bytes, use malloc().
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22''N, 111°50.29''W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.


" Chris Torek" <无**** @ torek.net>在消息中写道

news:cf ******** @ news3.newsguy.com ...
"Chris Torek" <no****@torek.net> wrote in message
news:cf********@news3.newsguy.com...
在文章< news:b8 **** **********************@posting.google。 com>
Harsimran< sa ************ @ yahoo.co.in>写道:
In article <news:b8**************************@posting.google. com>
Harsimran <sa************@yahoo.co.in> wrote:
和malloc和calloc有什么区别。哪个更好?
哪个更好,巧克力或草莓;椰子或酱油;锤子还是扳手?
and what is the difference between malloc and calloc .Which is better ?
Which is better, chocolate or strawberry; coconut or soy sauce;
a hammer or a wrench?




我宁愿被锤击而不是扭曲...

椰子酱???

如果你需要预先设置为''\0''的字节,你可以使用calloc();如果你只需要字节,请使用malloc()。



I''d rather be hammered than wrenched...

Coconut sauce???
If you need bytes pre-set to ''\0'' you can use calloc(); if you just
need bytes, use malloc().




对,如果你要去malloc()一些空间然后将它全部设置为零,你

也可以使用calloc()。这有时可能是懦夫的方式

out。如果你不认为你可以正确使用你的记忆,并且计算你所在的地址一次性时会出现

错误,那么很高兴有

归零大块内存的安全网 - 没有随机值。对于

实例,当在malloc''内存中存储字符串时,如果你忘记

终止''\0'',则calloc确保它已经存在。所以我说的是

是calloc()可以隐藏细微的错误和溢出,所以程序可能会工作,但是

仍然有bug。

我有时在开始开发时使用calloc,开始使用,并将
切换回malloc以查找真实代码的错误和溢出。但是很久以前这是一个

- 现在我想立即知道。


任何人都可以提出将原始归零的充分理由;在你用之前的记忆

甚至用过吗? ...也许是为了确保空的

字节对齐的零空间中有零???


-

Mabden

ps我以前错了......



Right, if you are going to malloc() some space then set it all to zero, you
might as well just use calloc(). This can sometimes be the "coward''s way
out". If you don''t think you can handle using your memory properly, and have
errors in calculating addresses where you are "one off", it''s nice to have
the safety net of a zeroed out chunk of memory - no random values. For
instance, when storing strings in malloc''ed memory, if you forget the
terminating ''\0'', the calloc assures it is already there. So what I''m saying
is calloc() can hide subtle bugs and overruns, so the program may work, but
still have bugs.
I sometimes used calloc in beginning development, to get going, and switched
back to malloc to find bugs and overruns for the real code. But that was a
long time ago - now I want to know right away.

Can anyone come up with a good reason to zero out "raw" memory before you''ve
even used it? ...maybe to make sure there are zeroes in the empty
byte-aligned null space???

--
Mabden
p.s. I''ve been wrong before...


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

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