发信人: 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);
: int* myp = new int;
: 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.]