wikipedia Tombstone (programming)
NOTE:
1、是在阅读 wikipedia Handle (computing) 时,发现的tombstone.
2、"tombstone"的表明意思是"墓石"。
3、Tombstone可以看做是handle的实现,它是abstraction layer、intermediary
4、tombstone非常类似于virtual address,它们背后的思想都是abstraction
Tombstones are a mechanism to detect dangling pointers that can appear in certain computer programming languages, e. g. C, C++ and assembly languages, and to act as a containment(围堵策略) to their dangerous effects.
Implementation
A tombstone is a structure that acts as an intermediary(中间人) between a pointer and the heap-dynamic data in memory. The pointer – sometimes called the handle – points only at tombstones and never to the memory that holds the actual value. When the data is deallocated, the tombstone is set to a null (or, more generally, to a value that is illegal for a pointer in the given runtime environment), indicating that the variable no longer exists. This prevents the use of invalid pointers, which would otherwise access the memory area that once belonged to the now deallocated variable, although it may already contain other data, in turn leading to corruption of in-memory data. Depending on the operating system, the CPU can automatically detect such an invalid access (e. g. for the null value: a null pointer dereference error). This supports in analyzing the actual reason, a programming error, in debugging, and it can also be used to abort the program in production use, to prevent it from continuing with invalid data structures.
Downside
NOTE:
1、performance tradeoff
The downsides of using tombstones include a computational overhead and additional memory consumption: extra processing is necessary to follow the path from the pointer to data through the tombstone, and extra memory is necessary to retain tombstones for every pointer throughout the program. One other problem is that all the code that needs to work with the pointers in question needs to be implemented to use the tombstone mechanism.