X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/0cbeddf886b3e6d732c96a8f6a578a755e7ddf66..8f41509fd52c574f447fe0e40555530de3fda431:/Pooling.hpp?ds=sidebyside diff --git a/Pooling.hpp b/Pooling.hpp index bd37c5c..e3116d9 100644 --- a/Pooling.hpp +++ b/Pooling.hpp @@ -62,6 +62,11 @@ class CYPool { return (size + 7) & ~0x3; } + template + static void delete_(void *data) { + reinterpret_cast(data)->~Type_(); + } + CYPool(const CYPool &); public: @@ -99,6 +104,8 @@ class CYPool { } char *strdup(const char *data) { + if (data == NULL) + return NULL; return reinterpret_cast(memdup(data, strlen(data) + 1)); } @@ -180,6 +187,13 @@ class CYPool { } void atexit(void (*code)(void *), void *data = NULL); + + template + Type_ &object() { + Type_ *value(new(*this) Type_()); + atexit(&delete_, value); + return *value; + } }; _finline void *operator new(size_t size, CYPool &pool) {