提交 3ae1d7bd 创建 作者: Nickolai Zeldovich's avatar Nickolai Zeldovich

placement new operators

上级 62934703
...@@ -130,13 +130,18 @@ extern "C" void __cxa_guard_abort(s64 *guard_object); ...@@ -130,13 +130,18 @@ extern "C" void __cxa_guard_abort(s64 *guard_object);
extern "C" int __cxa_atexit(void (*f)(void *), void *p, void *d); extern "C" int __cxa_atexit(void (*f)(void *), void *p, void *d);
extern void *__dso_handle; extern void *__dso_handle;
#define NEW_DELETE_OPS(classname) \ #define NEW_DELETE_OPS(classname) \
static void* operator new(unsigned long nbytes) { \ static void* operator new(unsigned long nbytes) { \
assert(nbytes == sizeof(classname)); \ assert(nbytes == sizeof(classname)); \
return kmalloc(sizeof(classname)); \ return kmalloc(sizeof(classname)); \
} \ } \
\ \
static void operator delete(void *p) { \ static void* operator new(unsigned long nbytes, classname *buf) { \
kmfree(p, sizeof(classname)); \ assert(nbytes == sizeof(classname)); \
return buf; \
} \
\
static void operator delete(void *p) { \
kmfree(p, sizeof(classname)); \
} }
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论