- ScopedAllocator() :
- next(0) {
- }
-
- inline void *
- alloc(size_t size) {
- /* Always return valid address, even when size is zero */
- size = std::max(size, sizeof(uintptr_t));
-
- uintptr_t * buf = static_cast<uintptr_t *>(malloc(sizeof(uintptr_t) + size));
- if (!buf) {
- return NULL;
- }
-
- *buf = next;
- next = reinterpret_cast<uintptr_t>(buf);
- assert((next & 1) == 0);
-
- return static_cast<void *>(&buf[1]);
- }
-
- template< class T >
- inline T *
- alloc(size_t n = 1) {
- return static_cast<T *>(alloc(sizeof(T) * n));
- }
-