mymemory: add placement new
authorBrian Norris <banorris@uci.edu>
Fri, 7 Dec 2012 05:50:33 +0000 (21:50 -0800)
committerBrian Norris <banorris@uci.edu>
Fri, 7 Dec 2012 06:41:29 +0000 (22:41 -0800)
I will need to use the placement new operator, if I want to allocate an
object with an allocator other than the one I established (SNAPSHOTALLOC
vs. MODELALLOC).

mymemory.h

index 05b89be959e0872386d955ebffd09b3b4076ffae..794c4e50cd1e1198ff6d9d8b86ba373114495e10 100644 (file)
@@ -23,6 +23,9 @@
        } \
        void operator delete[](void *p, size_t size) { \
                model_free(p); \
+       } \
+       void * operator new(size_t size, void *p) { /* placement new */ \
+               return p; \
        }
 
 /** SNAPSHOTALLOC declares the allocators for a class to allocate
@@ -39,6 +42,9 @@
        } \
        void operator delete[](void *p, size_t size) { \
                snapshot_free(p); \
+       } \
+       void * operator new(size_t size, void *p) { /* placement new */ \
+               return p; \
        }
 
 void *model_malloc(size_t size);