malloc函数仅在堆内存中分配吗? [英] Does malloc function only allocate in the heap memory?

查看:532
本文介绍了malloc函数仅在堆内存中分配吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

malloc函数仅在堆内存中分配吗?
调试模式 ?释放模式?

返回值是多少:

Does malloc function only allocate in the heap memory?
Debug mode ? Release mode?

What is the return value :

malloc(0)

推荐答案

是. Malloc始终返回指向堆内存的指针,而不返回堆栈.
C的某些实现将为malloc(0)返回一个空指针,但是通常很少见.通常,malloc(0)将返回一个空指针,该指针指向堆的零长度区域.这是一个有效的指针,但是您不应该尝试写它! (不过,它可以与realloc一起正常工作.)
Yes. Malloc always returns a pointer to heap memory, never stack.
Some implementations of C will return a null pointer for malloc(0), but these are generally rare. Normally malloc(0) will return a void pointer to a zero length area of the heap. It''s a valid pointer, but you shouldn''t try to write to it! (it will work fine with realloc though).


引用:

malloc函数仅在堆内存?

Does malloc function only allocate in the heap memory?

是.


Yes.


报价:

调试模式?是释放模式?

Debug mode ? Release mode?

在调试模式下,它可能会执行其他任务.


In debug mode it may perform additional tasks.


报价:

返回值是多少:
收合|复制代码
malloc(0)

What is the return value :
Collapse | Copy Code
malloc(0)

这取决于实现(您可能会得到0或有效地址,请参见 ^ ]).

It is implementation-dependent (you might get either 0 or a valid address, see here[^]).


这篇关于malloc函数仅在堆内存中分配吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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