Created
July 21, 2020 12:40
-
-
Save postwait/beb586466818d789e89c90e07ade2b51 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright (c) 2020, Circonus, Inc. | |
* All rights reserved. | |
*/ | |
#ifndef SNOWTH_UTIL_MTEV_MEMORY_SAFE_OBJECT_HPP | |
#define SNOWTH_UTIL_MTEV_MEMORY_SAFE_OBJECT_HPP | |
#include <mtev_memory.h> | |
class mtev_memory_safe_c { | |
public: | |
static void * operator new(size_t size) { return mtev_memory_safe_malloc(size); } | |
static void operator delete(void *p) { mtev_memory_safe_free(p); } | |
}; | |
class mtev_memory_safe_cleanup_c { | |
public: | |
static void * operator new(size_t size) { return mtev_memory_safe_malloc_cleanup(size, cleanup_op); } | |
virtual void mtev_memory_safe_cleanup() = 0; | |
static void operator delete(void *p) { mtev_memory_safe_free(p); } | |
private: | |
static void cleanup_op(void *p) { | |
mtev_memory_safe_cleanup_c *c = static_cast<mtev_memory_safe_cleanup_c *>(p); | |
c->mtev_memory_safe_cleanup(); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment