0

我有一棵树,我想释放分配的内存,但我面临一个问题,一个指针可能引用一个非动态分配的变量,所以如何知道这个指针是否引用动态变量

4

1 回答 1

0

This is compiler-specific. You may compare given pointer with pointer to a local variable. Result interpretation depends on the way compiler implements heap and stack. Generally, for given compiler, stack pointer is always less (or greater) than heap pointer. In any case, THIS IS BAD DESIGN. This may not work if pointer belongs to another heap (for example, allocated in another Dll).

于 2010-03-10T12:09:07.200 回答