当前在线人数13544
首页 - 分类讨论区 - 电脑网络 - 葵花宝典版 -阅读文章
未名交友
[更多]
[更多]
文章阅读:Re: how can free and delete know the boundary...
[同主题阅读] [版面: 葵花宝典] [作者:thrust] , 2005年05月17日11:34:59
thrust
进入未名形象秀
我的博客
[上篇] [下篇] [同主题上篇] [同主题下篇]

发信人: thrust (thrust), 信区: Programming
标  题: Re: how can free and delete know the boundary...
发信站: Unknown Space - 未名空间 (Tue May 17 11:35:41 2005), 转信

one common way is to place the size (and possibly other information)
before the pointer.


【 在 acan (阿灿哥) 的大作中提到: 】
: I think I never thought about this problem very carefully before.
: I just wonder how free() and delete know the size of the memory
: block which will be deallocated since the only argument of the function
: is the pointer.
:   char* myp = (char*)malloc(sizeof(char)*100);
:   free(myp);
:   int* myp = new int[100];
:   delete[] myp;
: The pointer is just an address, so free and delete must get the information
: from somewhere else. From some table or global area associated with the
: running process? What is that?
: Why not pass the size of the block to the free or delete?
: I know it is a fundmental question. Bow...


--
牙医, 牙医在哪儿?

※ 来源:.Unknown Space - 未名空间 mitbbs.com.[FROM: 128.205.]

[上篇] [下篇] [同主题上篇] [同主题下篇]
[转寄] [转贴] [回信给作者] [修改文章] [删除文章] [同主题阅读] [从此处展开] [返回版面] [快速返回] [收藏] [举报]
 
回复文章
标题:
内 容:

未名交友
将您的链接放在这儿

友情链接


 

Site Map - Contact Us - Terms and Conditions - Privacy Policy

版权所有,未名空间(mitbbs.com),since 1996