X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/5d5d70c083c2b891eb5382df084c90b0e2d406e5..ffc2d225884cc809328e19ecc318b4a5b84afe40:/Pooling.hpp?ds=sidebyside diff --git a/Pooling.hpp b/Pooling.hpp index 6225392..78aa1b2 100644 --- a/Pooling.hpp +++ b/Pooling.hpp @@ -43,6 +43,7 @@ class CYPool { private: uint8_t *data_; size_t size_; + size_t next_; struct Cleaner { Cleaner *next_; @@ -70,9 +71,10 @@ class CYPool { CYPool(const CYPool &); public: - CYPool() : + CYPool(size_t next = 64) : data_(NULL), size_(0), + next_(next), cleaner_(NULL) { } @@ -90,8 +92,8 @@ class CYPool { size = align(size); if (size > size_) { - // XXX: is this an optimal malloc size? - size_ = std::max(size, size + align(sizeof(Cleaner))); + size_ = std::max(next_, size + align(sizeof(Cleaner))); + next_ *= 2; data_ = reinterpret_cast(::malloc(size_)); atexit(free, data_); _assert(size <= size_); @@ -109,8 +111,9 @@ class CYPool { return reinterpret_cast(memdup(data, strlen(data) + 1)); } - void *memdup(const void *data, size_t size) { - void *copy(malloc(size)); + template + Type_ *memdup(const Type_ *data, size_t size) { + Type_ *copy(malloc(size)); memcpy(copy, data, size); return copy; }