summaryrefslogtreecommitdiffstats
path: root/vespalib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@oath.com>2018-05-29 18:11:08 +0200
committerHenning Baldersheim <balder@oath.com>2018-05-29 21:16:21 +0200
commitad673da96bb5772ff5cbcb8a5296e42c21f3bfac (patch)
tree9d8cbbaf3bc52fa53511dd8cea14c271c33798e4 /vespalib
parent10019f0ca6c04f8959c06acf8919b0fce212f5cb (diff)
Avoid crossing the creek multiple times to get an empty bucket of water.
Diffstat (limited to 'vespalib')
-rw-r--r--vespalib/src/vespa/vespalib/util/alloc.cpp10
-rw-r--r--vespalib/src/vespa/vespalib/util/alloc.h6
2 files changed, 14 insertions, 2 deletions
diff --git a/vespalib/src/vespa/vespalib/util/alloc.cpp b/vespalib/src/vespa/vespalib/util/alloc.cpp
index dff744a0a41..e4fb44bc618 100644
--- a/vespalib/src/vespa/vespalib/util/alloc.cpp
+++ b/vespalib/src/vespa/vespalib/util/alloc.cpp
@@ -213,6 +213,7 @@ alloc::AlignedHeapAllocator _G_4KalignedHeapAllocator(1024);
alloc::AlignedHeapAllocator _G_1KalignedHeapAllocator(4096);
alloc::AlignedHeapAllocator _G_512BalignedHeapAllocator(512);
alloc::MMapAllocator _G_mmapAllocatorDefault;
+alloc::MemoryAllocator *_G_defaultAutAllocator = nullptr;
}
@@ -466,6 +467,15 @@ Alloc::allocMMap(size_t sz)
}
Alloc
+Alloc::alloc()
+{
+ if (_G_defaultAutAllocator == nullptr) {
+ _G_defaultAutAllocator = &AutoAllocator::getDefault();
+ }
+ return Alloc(_G_defaultAutAllocator);
+}
+
+Alloc
Alloc::alloc(size_t sz, size_t mmapLimit, size_t alignment)
{
return Alloc(&AutoAllocator::getAllocator(mmapLimit, alignment), sz);
diff --git a/vespalib/src/vespa/vespalib/util/alloc.h b/vespalib/src/vespa/vespalib/util/alloc.h
index 2c3de92c58e..b52cace45a5 100644
--- a/vespalib/src/vespa/vespalib/util/alloc.h
+++ b/vespalib/src/vespa/vespalib/util/alloc.h
@@ -88,7 +88,7 @@ public:
std::swap(_allocator, rhs._allocator);
}
Alloc create(size_t sz) const {
- return Alloc(_allocator, sz);
+ return (sz == 0) ? Alloc(_allocator) : Alloc(_allocator, sz);
}
static Alloc allocAlignedHeap(size_t sz, size_t alignment);
@@ -98,9 +98,11 @@ public:
* Optional alignment is assumed to be <= system page size, since mmap
* is always used when size is above limit.
*/
- static Alloc alloc(size_t sz=0, size_t mmapLimit = MemoryAllocator::HUGEPAGE_SIZE, size_t alignment=0);
+ static Alloc alloc(size_t sz, size_t mmapLimit = MemoryAllocator::HUGEPAGE_SIZE, size_t alignment=0);
+ static Alloc alloc();
private:
Alloc(const MemoryAllocator * allocator, size_t sz) : _alloc(allocator->alloc(sz)), _allocator(allocator) { }
+ Alloc(const MemoryAllocator * allocator) : _alloc(nullptr, 0), _allocator(allocator) { }
void clear() {
_alloc.first = nullptr;
_alloc.second = 0;