4 ms·
If I am not wrong, there is a generation number embedded in the reference (smart pointer?). This allows to check if the generation of the reference and the gene
by conaclos 3y ago
If I am not wrong, there is a generation number embedded in the reference (smart pointer?). This allows to check if the generation of the reference and the generation of the referee match.
- marhee 3y agoYes, there is a generation number in the reference. It is checked against the generation number of the allocation that is stored in the allocation: void __check(GenerationalReference genRef) { uint64_t currentGeneration = *(uint64_t*)((char*)genRef.alloc - 8); assert(genRef.rememberedGeneration == currentGeneration); } So indeed you it allows you to check for a match, as long as the alloc pointer is valid. The alloc pointer is invalid after a free, because it maybe be in a region no longer accessible to the program (it was returned to the os by free's implementation) or it was given out as part of an other allocation, in which case it can hold arbitrary data.