lib
Class OverrunProtector
in allocators.h
- template < class T > class OverrunProtector
OverrunProtector wraps an arbitrary object in DynArray memory and can detect
inadvertent writes to it. this is useful for tracking down memory overruns.
the basic idea is to require users to request access to the object and
notify us when done; memory access permission is temporarily granted.
(similar in principle to Software Transaction Memory).
since this is quite slow, the protection is disabled unless
CONFIG_OVERRUN_PROTECTION == 1; this avoids having to remove the
wrapper code in release builds and re-write when looking for overruns.
example usage:
OverrunProtector your_class_wrapper;
..
yc = your_class_wrapper.get(); // unlock, make ready for use
if(!yc) // your_class_wrapper's one-time alloc of a your_class-
abort(); // instance had failed - can't continue.
doSomethingWith(yc); // read/write access
your_class_wrapper.lock(); // disallow further access until next .get()
..
cached_ptr
private T* cached_ptr;
da
private DynArray da;
initialized
private uintptr_t initialized;
OverrunProtector
public OverrunProtector();
~OverrunProtector
public ~OverrunProtector();
get
public T* get();
init
private void init();
lock
public void lock();
shutdown
private void shutdown();
unlock
private void unlock();