remove unused #define
[c11tester.git] / mymemory.cc
index f43f1c35c7e561b1610edfc64899e84a0b07b6ac..1af6109725978bc39e36964c9a964f31acc56346 100644 (file)
@@ -1,15 +1,13 @@
-
 #include "mymemory.h"
 #include "snapshot.h"
 #include "snapshotimp.h"
 #include <stdio.h>
 #include <dlfcn.h>
-#define MSPACE_SIZE ( 1 << 20 )
 #if !USE_CHECKPOINTING
 static mspace sStaticSpace = NULL;
 #endif
-void *MYMALLOC(size_t size)
-{
+
+void *MYMALLOC(size_t size) {
 #if USE_CHECKPOINTING
   static void *(*mallocp)(size_t size);
   char *error;
@@ -17,11 +15,11 @@ void *MYMALLOC(size_t size)
 
   /* get address of libc malloc */
   if (!mallocp) {
-  mallocp = ( void * ( * )( size_t ) )dlsym(RTLD_NEXT, "malloc");
-  if ((error = dlerror()) != NULL) {
+    mallocp = ( void * ( * )( size_t ) )dlsym(RTLD_NEXT, "malloc");
+    if ((error = dlerror()) != NULL) {
       fputs(error, stderr);
       exit(1);
-  }
+    }
   }
   ptr = mallocp(size);     
   return ptr;
@@ -30,13 +28,12 @@ void *MYMALLOC(size_t size)
     createSharedLibrary();
   }
   if( NULL == sStaticSpace )
-  sStaticSpace = create_mspace_with_base( ( void * )( sTheRecord->mSharedMemoryBase ), SHARED_MEMORY_DEFAULT -sizeof( struct Snapshot_t ), 1 );
+    sStaticSpace = create_mspace_with_base( ( void * )( sTheRecord->mSharedMemoryBase ), SHARED_MEMORY_DEFAULT -sizeof( struct Snapshot_t ), 1 );
   return mspace_malloc( sStaticSpace, size );
 #endif
 }
 
-void MYFREE(void *ptr)
-{
+void MYFREE(void *ptr) {
 #if USE_CHECKPOINTING
   static void (*freep)(void *);
   char *error;
@@ -54,16 +51,19 @@ void MYFREE(void *ptr)
   mspace_free( sStaticSpace, ptr );
 #endif
 }
-static mspace mySpace = NULL;
-void *malloc( size_t size ){
-       if( NULL == mySpace ){
-               //void * mem = MYMALLOC( MSPACE_SIZE );
-               mySpace = create_mspace( MSPACE_SIZE, 1 );
-       }
-       return mspace_malloc( mySpace, size );
+mspace mySpace = NULL;
+void *malloc( size_t size ) {
+  return mspace_malloc( mySpace, size );
 }
 
 void free( void * ptr ){
-       mspace_free( mySpace, ptr );
+  mspace_free( mySpace, ptr );
+}
+
+void * operator new(size_t size) throw(std::bad_alloc) {
+  return MYMALLOC(size);
 }
 
+void operator delete(void *p) throw() {
+  MYFREE(p);
+}