private:
uint8_t *data_;
size_t size_;
+ size_t next_;
struct Cleaner {
Cleaner *next_;
CYPool(const CYPool &);
public:
- CYPool() :
+ CYPool(size_t next = 64) :
data_(NULL),
size_(0),
+ next_(next),
cleaner_(NULL)
{
}
size = align(size);
if (size > size_) {
- // XXX: is this an optimal malloc size?
- size_ = std::max<size_t>(size, size + align(sizeof(Cleaner)));
+ size_ = std::max<size_t>(next_, size + align(sizeof(Cleaner)));
+ next_ *= 2;
data_ = reinterpret_cast<uint8_t *>(::malloc(size_));
atexit(free, data_);
_assert(size <= size_);
return copy;
}
- char *strndup(const char *data, size_t size) const {
+ char *strndup(const char *data, size_t size) {
return strmemdup(data, strnlen(data, size));
}
- char *strmemdup(const char *data, size_t size) const {
- char *copy(new char[size + 1]);
+ char *strmemdup(const char *data, size_t size) {
+ char *copy(malloc<char>(size + 1));
memcpy(copy, data, size);
copy[size] = '\0';
return copy;