diff options
author | Daniel Wilhelm <daniel@wili.li> | 2015-10-02 14:56:07 +0200 |
---|---|---|
committer | Daniel Wilhelm <daniel@wili.li> | 2015-10-02 14:56:07 +0200 |
commit | de73d25e0b27f4bee2de116d19cab32800785d64 (patch) | |
tree | 21de1736d12a92223ad04c02a5b0826d77e5e71c /zen/string_base.h | |
parent | 7.1 (diff) | |
download | FreeFileSync-de73d25e0b27f4bee2de116d19cab32800785d64.tar.gz FreeFileSync-de73d25e0b27f4bee2de116d19cab32800785d64.tar.bz2 FreeFileSync-de73d25e0b27f4bee2de116d19cab32800785d64.zip |
7.2
Diffstat (limited to 'zen/string_base.h')
-rw-r--r-- | zen/string_base.h | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/zen/string_base.h b/zen/string_base.h index be3b532e..f4ca5f2e 100644 --- a/zen/string_base.h +++ b/zen/string_base.h @@ -28,8 +28,8 @@ class AllocatorOptimalSpeed //exponential growth + min size { public: //::operator new/ ::operator delete show same performance characterisics like malloc()/free()! - static void* allocate(size_t size) { return ::operator new(size); } //throw std::bad_alloc - static void deallocate(void* ptr) { ::operator delete(ptr); } + static void* allocate(size_t size) { return ::malloc(size); } //throw std::bad_alloc + static void deallocate(void* ptr) { ::free(ptr); } static size_t calcCapacity(size_t length) { return std::max<size_t>(16, std::max(length + length / 2, length)); } //- size_t might overflow! => better catch here than return a too small size covering up the real error: a way too large length! //- any growth rate should not exceed golden ratio: 1.618033989 @@ -39,8 +39,8 @@ public: class AllocatorOptimalMemory //no wasted memory, but more reallocations required when manipulating string { public: - static void* allocate(size_t size) { return ::operator new(size); } //throw std::bad_alloc - static void deallocate(void* ptr) { ::operator delete(ptr); } + static void* allocate(size_t size) { return ::malloc(size); } //throw std::bad_alloc + static void deallocate(void* ptr) { ::free(ptr); } static size_t calcCapacity(size_t length) { return length; } }; @@ -148,9 +148,21 @@ protected: return ptr; } +#ifdef NDEBUG void destroy(Char* ptr) +#else + void destroy(Char*& ptr) +#endif { - if (!ptr) return; //support "destroy(nullptr)" + assert(ptr != reinterpret_cast<Char*>(0x1)); //detect double-deletion + + if (!ptr) //support "destroy(nullptr)" + { +#ifndef NDEBUG + ptr = reinterpret_cast<Char*>(0x1); +#endif + return; + } Descriptor* const d = descr(ptr); @@ -158,6 +170,9 @@ protected: { d->~Descriptor(); this->deallocate(d); +#ifndef NDEBUG + ptr = reinterpret_cast<Char*>(0x1); +#endif } } |