Redian新闻
>
求平时日常使用的visa or MasterCard
avatar
求平时日常使用的visa or MasterCard# Money - 海外理财
h*g
1
if free an obj initiated on stack, what happened? what about on heap
avatar
z*a
2
用哪个反点价值最大的
暂时不考虑年费的话。
谢谢
★ 发自iPhone App: ChineseWeb 7.3
avatar
c*2
3
stack: double free? (it's supposed to be managed by OS)
heap: normal use, you always need to free it since it's allocated by you.
avatar
d*l
4
不考虑年费是什么意思?

【在 z******a 的大作中提到】
: 用哪个反点价值最大的
: 暂时不考虑年费的话。
: 谢谢
: ★ 发自iPhone App: ChineseWeb 7.3

avatar
t*t
5
前一个是undefined behavior
avatar
G*s
6
据说美洲用visa更方便,欧洲用mc更多,中国用银联

【在 d**l 的大作中提到】
: 不考虑年费是什么意思?
avatar
p*x
7

stack frames的管理是由编译器决定
管理stack 的指令由编译器插入你程序的二进制代码中
malloc() and free()都是针对heap的,不是针对stack.
double free buffers in stack?
可能会有出错信息,这取决于你的heap管理。
如果你用free(buf1), buf1不在heap范围,会出错。
对于heap 的buffer, 每个buffer块也是按照大小分别管理的
每个buffer块都有meta data指出该块范围等信息。
如果用C/C++.需要
如果是用java,python等,由VM或者interpreter负责管理heap.

【在 c***2 的大作中提到】
: stack: double free? (it's supposed to be managed by OS)
: heap: normal use, you always need to free it since it's allocated by you.

avatar
G*L
8
据谁说的?

据说美洲用visa更方便,欧洲用mc更多,中国用银联
~~~~~~~~~~~~~~~~~~~~

【在 G*******s 的大作中提到】
: 据说美洲用visa更方便,欧洲用mc更多,中国用银联
avatar
f*y
9
the heap one is easy. if you free an obj on stack, when the stack pop its
content, it will de-reference a piece of memory that stack no longer owns (
an dangling pointer), so the result is undefined.
avatar
h*s
10
priceline 2%

【在 z******a 的大作中提到】
: 用哪个反点价值最大的
: 暂时不考虑年费的话。
: 谢谢
: ★ 发自iPhone App: ChineseWeb 7.3

avatar
c*t
11
写了一个很简单的程序,在linux下试了试,是segmentation fault, 程序退出。并且用
valgrind verify了一下,是同样的结果。
#include
// del_stack_variable.c
// this program tries to delete a variable in a function
//
int main()
{
int j=10;
printf("the addr of j =%p, j = %d\n", &j, j);
printf("delete j \n");
free(&j); //this will cause segmentation fault
printf("after that\n");
printf("the addr of j =%p, j = %d\n", &j, j);
return 0;
}
gcc -o del_stack del_stack_variable.c
$ ./del_stack
the addr of j =0xbff6c4b0, j = 10
delete j
Segmentation fault
$ valgrind ./del_stack
the addr of j =0xbe9374e0, j = 10
delete j
==27295== Invalid free() / delete / delete[]
==27295==
==27295== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 12 from 1)
==27295== malloc/free: in use at exit: 0 bytes in 0 blocks.
==27295== malloc/free: 0 allocs, 1 frees, 0 bytes allocated.
==27295== For counts of detected errors, rerun with: -v
==27295== All heap blocks were freed -- no leaks are possible.

【在 h*****g 的大作中提到】
: if free an obj initiated on stack, what happened? what about on heap
avatar
h*a
12
上帝说的。

【在 G*L 的大作中提到】
: 据谁说的?
:
: 据说美洲用visa更方便,欧洲用mc更多,中国用银联
: ~~~~~~~~~~~~~~~~~~~~

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。