On Wednesday, 13 November 2013 at 00:33:17 UTC, Andrei
Alexandrescu wrote:
Hello,
I will soon get to work on typed allocators; I figured there
will be some issues percolating to untyped allocators that will
require design changes (hopefully minor).
For starters, I want to define a function that "obliterates" an
object, i.e. makes it almost surely unusable and not obeying
its own invariants. At the same time, that state should be
entirely reproducible and memory-safe.
Here's what I'm thinking. First, obliterate calls the
destructor if present and then writes the fields as follows:
* unsigned integers: t.max / 2
* signed integers: t.min / 2
* characters: ?
* Pointers and class references: size_t.max - 65_535, i.e. 64K
below the upper memory limit. On all systems I know it can be
safely assumed that that area will cause GPF when accessed.
* Arrays: some weird length (like 17), and also starting at
size_t.max minus the memory occupied by the array.
* floating point numbers: NaN, or some ridiculous value like
F.max / 2?
Andrei
Perhaps these are of interest:
http://stackoverflow.com/a/127404/216300