summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2016-10-16 19:47:08 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2016-10-16 19:47:08 +0000
commit3dc92c36aa6f58a2ce2f57089501364dab6a44bc (patch)
treed48b2ca1cee14621dd7c51e3a6ba089ca18e43fe
parent1ab845031009400d8222f2c4affffaeaba3ccd71 (diff)
Remove the XXXFactory indirection. Just use static method on Alloc.
-rw-r--r--config/src/vespa/config/frt/protocol.cpp2
-rw-r--r--document/src/vespa/document/fieldvalue/fieldvalue.cpp1
-rw-r--r--document/src/vespa/document/util/bytebuffer.cpp9
-rw-r--r--document/src/vespa/document/util/compressor.cpp5
-rw-r--r--document/src/vespa/document/util/serializable.cpp2
-rw-r--r--fastlib/src/vespa/fastlib/io/bufferedfile.cpp2
-rw-r--r--fnet/src/vespa/fnet/databuffer.cpp8
-rw-r--r--fnet/src/vespa/fnet/frt/values.h9
-rw-r--r--memfilepersistence/src/vespa/memfilepersistence/mapper/buffer.cpp3
-rw-r--r--memfilepersistence/src/vespa/memfilepersistence/mapper/simplememfileiobuffer.h2
-rw-r--r--messagebus/src/vespa/messagebus/blob.h9
-rw-r--r--searchcore/src/apps/vespa-gen-testdocs/vespa-gen-testdocs.cpp3
-rw-r--r--searchlib/src/tests/datastore/logdatastore_test.cpp3
-rw-r--r--searchlib/src/vespa/searchlib/attribute/loadedstringvalue.cpp4
-rw-r--r--searchlib/src/vespa/searchlib/btree/bufferstate.cpp5
-rw-r--r--searchlib/src/vespa/searchlib/common/allocatedbitvector.cpp3
-rw-r--r--searchlib/src/vespa/searchlib/common/bitvector.cpp4
-rw-r--r--searchlib/src/vespa/searchlib/common/partialbitvector.cpp6
-rw-r--r--searchlib/src/vespa/searchlib/common/resultset.cpp5
-rw-r--r--searchlib/src/vespa/searchlib/common/sortresults.cpp45
-rw-r--r--searchlib/src/vespa/searchlib/docstore/compacter.cpp4
-rw-r--r--searchlib/src/vespa/searchlib/docstore/documentstore.h5
-rw-r--r--searchlib/src/vespa/searchlib/docstore/visitcache.cpp5
-rw-r--r--searchlib/src/vespa/searchlib/grouping/sketch.h2
-rw-r--r--searchlib/src/vespa/searchlib/queryeval/predicate_blueprint.cpp2
-rw-r--r--searchlib/src/vespa/searchlib/queryeval/predicate_blueprint.h3
-rw-r--r--searchlib/src/vespa/searchlib/transactionlog/domainpart.cpp20
-rw-r--r--staging_vespalib/src/tests/memorydatastore/memorydatastore.cpp2
-rw-r--r--staging_vespalib/src/vespa/vespalib/data/databuffer.h8
-rw-r--r--staging_vespalib/src/vespa/vespalib/util/growablebytebuffer.cpp4
-rw-r--r--storageapi/src/vespa/storageapi/mbusprot/storagereply.cpp3
-rw-r--r--vespalib/src/tests/alloc/alloc_test.cpp16
-rw-r--r--vespalib/src/tests/alloc/allocate_and_core.cpp4
-rw-r--r--vespalib/src/vespa/vespalib/data/memorydatastore.cpp2
-rw-r--r--vespalib/src/vespa/vespalib/data/memorydatastore.h2
-rw-r--r--vespalib/src/vespa/vespalib/util/alloc.cpp10
-rw-r--r--vespalib/src/vespa/vespalib/util/alloc.h43
-rw-r--r--vespalib/src/vespa/vespalib/util/array.h8
38 files changed, 113 insertions, 160 deletions
diff --git a/config/src/vespa/config/frt/protocol.cpp b/config/src/vespa/config/frt/protocol.cpp
index 5c7af53d2af..43eba571083 100644
--- a/config/src/vespa/config/frt/protocol.cpp
+++ b/config/src/vespa/config/frt/protocol.cpp
@@ -59,7 +59,7 @@ const Memory RESPONSE_COMPRESSION_INFO_UNCOMPRESSED_SIZE = "uncompressedSize";
DecompressedData
decompress_lz4(const char * input, uint32_t inputLen, int uncompressedLength)
{
- Alloc memory( DefaultAlloc::create(uncompressedLength));
+ Alloc memory( Alloc::alloc(uncompressedLength));
int sz = LZ4_decompress_safe(input, static_cast<char *>(memory.get()), inputLen, uncompressedLength);
if (sz >= 0 && sz != uncompressedLength) {
if (LOG_WOULD_LOG(debug)) {
diff --git a/document/src/vespa/document/fieldvalue/fieldvalue.cpp b/document/src/vespa/document/fieldvalue/fieldvalue.cpp
index 8a9b332709b..20568ea2a5c 100644
--- a/document/src/vespa/document/fieldvalue/fieldvalue.cpp
+++ b/document/src/vespa/document/fieldvalue/fieldvalue.cpp
@@ -23,7 +23,6 @@
using vespalib::FieldBase;
using vespalib::nbostream;
-using vespalib::DefaultAlloc;
namespace document {
diff --git a/document/src/vespa/document/util/bytebuffer.cpp b/document/src/vespa/document/util/bytebuffer.cpp
index 4c8116482d5..f6a0bfda3c9 100644
--- a/document/src/vespa/document/util/bytebuffer.cpp
+++ b/document/src/vespa/document/util/bytebuffer.cpp
@@ -22,7 +22,6 @@
#define LOG_DEBUG4(a,b,c,d) LOG_DEBUG1(vespalib::make_string(a,b,c,d));
using vespalib::alloc::Alloc;
-using vespalib::DefaultAlloc;
namespace document {
@@ -60,7 +59,7 @@ ByteBuffer::ByteBuffer() :
}
ByteBuffer::ByteBuffer(size_t len) :
- ByteBuffer(DefaultAlloc::create(len), len)
+ ByteBuffer(Alloc::alloc(len), len)
{
}
@@ -115,7 +114,7 @@ ByteBuffer& ByteBuffer::operator=(const ByteBuffer & org)
if (this != & org) {
cleanUp();
if (org._len > 0 && org._buffer) {
- DefaultAlloc::create(org._len + 1).swap(_ownedBuffer);
+ Alloc::alloc(org._len + 1).swap(_ownedBuffer);
_buffer = static_cast<char *>(_ownedBuffer.get());
memcpy(_buffer,org._buffer,org._len);
_buffer[org._len] = 0;
@@ -190,7 +189,7 @@ ByteBuffer::sliceFrom(const ByteBuffer& buf, size_t from, size_t to) // throw (B
// Slicing from someone that doesn't own their buffer, must make own copy.
if (( buf._ownedBuffer.get() == NULL ) && (buf._bufHolder == NULL)) {
cleanUp();
- DefaultAlloc::create(to-from + 1).swap(_ownedBuffer);
+ Alloc::alloc(to-from + 1).swap(_ownedBuffer);
_buffer = static_cast<char *>(_ownedBuffer.get());
memcpy(_buffer, buf._buffer + from, to-from);
_buffer[to-from] = 0;
@@ -219,7 +218,7 @@ ByteBuffer::sliceFrom(const ByteBuffer& buf, size_t from, size_t to) // throw (B
ByteBuffer* ByteBuffer::copyBuffer(const char* buffer, size_t len)
{
if (buffer && len) {
- Alloc newBuf = DefaultAlloc::create(len + 1);
+ Alloc newBuf = Alloc::alloc(len + 1);
memcpy(newBuf.get(), buffer, len);
static_cast<char *>(newBuf.get())[len] = 0;
return new ByteBuffer(std::move(newBuf), len);
diff --git a/document/src/vespa/document/util/compressor.cpp b/document/src/vespa/document/util/compressor.cpp
index 9f0c6913325..062722292c2 100644
--- a/document/src/vespa/document/util/compressor.cpp
+++ b/document/src/vespa/document/util/compressor.cpp
@@ -12,7 +12,6 @@ LOG_SETUP(".document.compressor");
#include <lz4hc.h>
using vespalib::alloc::Alloc;
-using vespalib::DefaultAlloc;
using vespalib::ConstBufferRef;
using vespalib::DataBuffer;
using vespalib::make_string;
@@ -30,10 +29,10 @@ LZ4Compressor::process(const CompressionConfig& config, const void * inputV, siz
char * output(static_cast<char *>(outputV));
int sz(-1);
if (config.compressionLevel > 6) {
- Alloc state = DefaultAlloc::create(LZ4_sizeofStateHC());
+ Alloc state = Alloc::alloc(LZ4_sizeofStateHC());
sz = LZ4_compressHC2_withStateHC(state.get(), input, output, inputLen, config.compressionLevel);
} else {
- Alloc state = DefaultAlloc::create(LZ4_sizeofState());
+ Alloc state = Alloc::alloc(LZ4_sizeofState());
sz = LZ4_compress_withState(state.get(), input, output, inputLen);
}
if (sz != 0) {
diff --git a/document/src/vespa/document/util/serializable.cpp b/document/src/vespa/document/util/serializable.cpp
index 2e9ea321b8f..c6738374223 100644
--- a/document/src/vespa/document/util/serializable.cpp
+++ b/document/src/vespa/document/util/serializable.cpp
@@ -6,8 +6,6 @@
#include <stdio.h>
#include <vespa/document/util/bytebuffer.h>
-using vespalib::DefaultAlloc;
-
namespace document {
IMPLEMENT_IDENTIFIABLE_ABSTRACT(Serializable, vespalib::Identifiable);
diff --git a/fastlib/src/vespa/fastlib/io/bufferedfile.cpp b/fastlib/src/vespa/fastlib/io/bufferedfile.cpp
index adf201a6e1e..8d5aef0c097 100644
--- a/fastlib/src/vespa/fastlib/io/bufferedfile.cpp
+++ b/fastlib/src/vespa/fastlib/io/bufferedfile.cpp
@@ -392,7 +392,7 @@ size_t computeBufLen(size_t buflen)
Fast_BufferedFile::Fast_BufferedFile(FastOS_FileInterface *file, size_t bufferSize) :
FastOS_FileInterface(),
_fileleft(static_cast<uint64_t>(-1)),
- _buf(vespalib::alloc::MMapAllocFactory::create(computeBufLen(bufferSize))),
+ _buf(vespalib::alloc::Alloc::allocMMap(computeBufLen(bufferSize))),
_bufi(NULL),
_bufe(NULL),
_filepos(0),
diff --git a/fnet/src/vespa/fnet/databuffer.cpp b/fnet/src/vespa/fnet/databuffer.cpp
index 913196d6e72..578faba1e49 100644
--- a/fnet/src/vespa/fnet/databuffer.cpp
+++ b/fnet/src/vespa/fnet/databuffer.cpp
@@ -3,8 +3,6 @@
#include <vespa/fastos/fastos.h>
#include <vespa/fnet/fnet.h>
-using vespalib::DefaultAlloc;
-
FNET_DataBuffer::FNET_DataBuffer(uint32_t len)
: _bufstart(NULL),
_bufend(NULL),
@@ -15,7 +13,7 @@ FNET_DataBuffer::FNET_DataBuffer(uint32_t len)
len = 256;
if (len > 0) {
- DefaultAlloc::create(len).swap(_ownedBuf);
+ Alloc::alloc(len).swap(_ownedBuf);
memset(_ownedBuf.get(), 0x55, len);
_bufstart = static_cast<char *>(_ownedBuf.get());
assert(_bufstart != NULL);
@@ -72,7 +70,7 @@ FNET_DataBuffer::Shrink(uint32_t newsize)
return false;
}
- Alloc newBuf(DefaultAlloc::create(newsize));
+ Alloc newBuf(Alloc::alloc(newsize));
memset(newBuf.get(), 0x55, newsize);
memcpy(newBuf.get(), _datapt, GetDataLen());
_ownedBuf.swap(newBuf);
@@ -97,7 +95,7 @@ FNET_DataBuffer::Pack(uint32_t needbytes)
while (bufsize - GetDataLen() < needbytes)
bufsize *= 2;
- Alloc newBuf(DefaultAlloc::create(bufsize));
+ Alloc newBuf(Alloc::alloc(bufsize));
memset(newBuf.get(), 0x55, bufsize);
memcpy(newBuf.get(), _datapt, GetDataLen());
_ownedBuf.swap(newBuf);
diff --git a/fnet/src/vespa/fnet/frt/values.h b/fnet/src/vespa/fnet/frt/values.h
index 8ab8914d31f..7e889466941 100644
--- a/fnet/src/vespa/fnet/frt/values.h
+++ b/fnet/src/vespa/fnet/frt/values.h
@@ -71,13 +71,14 @@ class FRT_Values
public:
class LocalBlob : public FRT_ISharedBlob
{
+ using Alloc = vespalib::alloc::Alloc;
public:
- LocalBlob(vespalib::alloc::Alloc data, uint32_t len) :
+ LocalBlob(Alloc data, uint32_t len) :
_data(std::move(data)),
_len(len)
{ }
LocalBlob(const char *data, uint32_t len) :
- _data(vespalib::DefaultAlloc::create(len)),
+ _data(Alloc::alloc(len)),
_len(len)
{
if (data != NULL) {
@@ -85,7 +86,7 @@ public:
}
}
void addRef() override {}
- void subRef() override { vespalib::alloc::Alloc().swap(_data); }
+ void subRef() override { Alloc().swap(_data); }
uint32_t getLen() override { return _len; }
const char *getData() override { return static_cast<const char *>(_data.get()); }
char *getInternalData() { return static_cast<char *>(_data.get()); }
@@ -93,7 +94,7 @@ public:
LocalBlob(const LocalBlob &);
LocalBlob &operator=(const LocalBlob &);
- vespalib::alloc::Alloc _data;
+ Alloc _data;
uint32_t _len;
};
diff --git a/memfilepersistence/src/vespa/memfilepersistence/mapper/buffer.cpp b/memfilepersistence/src/vespa/memfilepersistence/mapper/buffer.cpp
index a998bb7d90e..acf7ac6a69d 100644
--- a/memfilepersistence/src/vespa/memfilepersistence/mapper/buffer.cpp
+++ b/memfilepersistence/src/vespa/memfilepersistence/mapper/buffer.cpp
@@ -5,7 +5,6 @@
#include <algorithm>
#include <stdlib.h>
-using vespalib::DefaultAlloc;
using vespalib::alloc::MemoryAllocator;
using vespalib::alloc::Alloc;
@@ -16,7 +15,7 @@ namespace memfile {
// It is crucial that any backing buffer type returns an address that is
// 512-byte aligned, or direct IO will scream at us and fail everything.
Buffer::Buffer(size_t size)
- : _buffer(DefaultAlloc::create(size, MemoryAllocator::HUGEPAGE_SIZE, 512)),
+ : _buffer(Alloc::alloc(size, MemoryAllocator::HUGEPAGE_SIZE, 512)),
_size(size)
{
}
diff --git a/memfilepersistence/src/vespa/memfilepersistence/mapper/simplememfileiobuffer.h b/memfilepersistence/src/vespa/memfilepersistence/mapper/simplememfileiobuffer.h
index c564893a154..d305d6a8e25 100644
--- a/memfilepersistence/src/vespa/memfilepersistence/mapper/simplememfileiobuffer.h
+++ b/memfilepersistence/src/vespa/memfilepersistence/mapper/simplememfileiobuffer.h
@@ -77,7 +77,7 @@ public:
typedef vespalib::LinkedPtr<SharedBuffer> LP;
explicit SharedBuffer(size_t totalSize)
- : _buf(vespalib::alloc::MMapAllocFactory::create(totalSize)),
+ : _buf(vespalib::alloc::Alloc::allocMMap(totalSize)),
_usedSize(0)
{
}
diff --git a/messagebus/src/vespa/messagebus/blob.h b/messagebus/src/vespa/messagebus/blob.h
index 86e317d6e79..ab915e7ce1c 100644
--- a/messagebus/src/vespa/messagebus/blob.h
+++ b/messagebus/src/vespa/messagebus/blob.h
@@ -14,6 +14,7 @@ namespace mbus {
**/
class Blob
{
+ using Alloc = vespalib::alloc::Alloc;
public:
/**
* Create a blob that will contain uninitialized memory with the
@@ -22,7 +23,7 @@ public:
* @param s size of the data to be created
**/
Blob(uint32_t s) :
- _payload(vespalib::DefaultAlloc::create(s)),
+ _payload(Alloc::alloc(s)),
_sz(s)
{ }
Blob(Blob && rhs) :
@@ -55,11 +56,11 @@ public:
**/
const char *data() const { return static_cast<const char *>(_payload.get()); }
- vespalib::alloc::Alloc & payload() { return _payload; }
- const vespalib::alloc::Alloc & payload() const { return _payload; }
+ Alloc & payload() { return _payload; }
+ const Alloc & payload() const { return _payload; }
size_t size() const { return _sz; }
private:
- vespalib::alloc::Alloc _payload;
+ Alloc _payload;
size_t _sz;
};
diff --git a/searchcore/src/apps/vespa-gen-testdocs/vespa-gen-testdocs.cpp b/searchcore/src/apps/vespa-gen-testdocs/vespa-gen-testdocs.cpp
index 1983ff7a318..f57e464fae6 100644
--- a/searchcore/src/apps/vespa-gen-testdocs/vespa-gen-testdocs.cpp
+++ b/searchcore/src/apps/vespa-gen-testdocs/vespa-gen-testdocs.cpp
@@ -17,7 +17,6 @@ typedef vespalib::hash_set<uint32_t> UIntSet;
typedef std::vector<vespalib::string> StringArray;
typedef std::shared_ptr<StringArray> StringArraySP;
using namespace vespalib::alloc;
-using vespalib::DefaultAlloc;
using vespalib::string;
void
@@ -49,7 +48,7 @@ shafile(const string &baseDir,
string fullFile(prependBaseDir(baseDir, file));
FastOS_File f;
std::ostringstream os;
- Alloc buf = DefaultAlloc::create(65536, MemoryAllocator::HUGEPAGE_SIZE, 0x1000);
+ Alloc buf = Alloc::alloc(65536, MemoryAllocator::HUGEPAGE_SIZE, 0x1000);
f.EnableDirectIO();
bool openres = f.OpenReadOnly(fullFile.c_str());
if (!openres) {
diff --git a/searchlib/src/tests/datastore/logdatastore_test.cpp b/searchlib/src/tests/datastore/logdatastore_test.cpp
index 00d4568df3e..7c558c2119d 100644
--- a/searchlib/src/tests/datastore/logdatastore_test.cpp
+++ b/searchlib/src/tests/datastore/logdatastore_test.cpp
@@ -20,7 +20,6 @@ using document::BucketId;
using namespace search::docstore;
using namespace search;
using namespace vespalib::alloc;
-using vespalib::DefaultAlloc;
using search::index::DummyFileHeaderContext;
class MyTlSyncer : public transactionlog::SyncProxy {
@@ -146,7 +145,7 @@ TEST("test that DirectIOPadding works accordng to spec") {
FastOS_File file("directio.test");
file.EnableDirectIO();
EXPECT_TRUE(file.OpenReadWrite());
- Alloc buf(DefaultAlloc::create(FILE_SIZE, MemoryAllocator::HUGEPAGE_SIZE, 4096));
+ Alloc buf(Alloc::alloc(FILE_SIZE, MemoryAllocator::HUGEPAGE_SIZE, 4096));
memset(buf.get(), 'a', buf.size());
EXPECT_EQUAL(FILE_SIZE, file.Write2(buf.get(), FILE_SIZE));
size_t padBefore(0);
diff --git a/searchlib/src/vespa/searchlib/attribute/loadedstringvalue.cpp b/searchlib/src/vespa/searchlib/attribute/loadedstringvalue.cpp
index 478b7a5e7a9..954e4342466 100644
--- a/searchlib/src/vespa/searchlib/attribute/loadedstringvalue.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/loadedstringvalue.cpp
@@ -4,7 +4,7 @@
#include "loadedstringvalue.h"
using vespalib::Array;
-using vespalib::alloc::MMapAllocFactory;
+using vespalib::alloc::Alloc;
namespace search {
@@ -13,7 +13,7 @@ namespace attribute {
void
sortLoadedByValue(LoadedStringVectorReal &loaded)
{
- Array<unsigned> radixScratchPad(loaded.size(), MMapAllocFactory::create());
+ Array<unsigned> radixScratchPad(loaded.size(), Alloc::allocMMap());
for(size_t i(0), m(loaded.size()); i < m; i++) {
loaded[i].prepareRadixSort();
}
diff --git a/searchlib/src/vespa/searchlib/btree/bufferstate.cpp b/searchlib/src/vespa/searchlib/btree/bufferstate.cpp
index 36e63300034..31e3a6c3e3f 100644
--- a/searchlib/src/vespa/searchlib/btree/bufferstate.cpp
+++ b/searchlib/src/vespa/searchlib/btree/bufferstate.cpp
@@ -3,7 +3,6 @@
#include "bufferstate.h"
#include <limits>
-using vespalib::DefaultAlloc;
using vespalib::alloc::Alloc;
namespace search {
@@ -125,7 +124,7 @@ BufferState::BufferState(void)
_typeId(0),
_clusterSize(0),
_compacting(false),
- _buffer(DefaultAlloc::create())
+ _buffer(Alloc::alloc())
{
}
@@ -216,7 +215,7 @@ BufferState::onFree(void *&buffer)
assert(_deadElems <= _usedElems);
assert(_holdElems == _usedElems - _deadElems);
_typeHandler->destroyElements(buffer, _usedElems);
- DefaultAlloc::create().swap(_buffer);
+ Alloc::alloc().swap(_buffer);
_typeHandler->onFree(_usedElems);
buffer = NULL;
_usedElems = 0;
diff --git a/searchlib/src/vespa/searchlib/common/allocatedbitvector.cpp b/searchlib/src/vespa/searchlib/common/allocatedbitvector.cpp
index 255ee64633d..5c4477b9f97 100644
--- a/searchlib/src/vespa/searchlib/common/allocatedbitvector.cpp
+++ b/searchlib/src/vespa/searchlib/common/allocatedbitvector.cpp
@@ -11,14 +11,13 @@ using vespalib::nbostream;
using vespalib::GenerationHeldBase;
using vespalib::GenerationHeldAlloc;
using vespalib::GenerationHolder;
-using vespalib::DefaultAlloc;
void AllocatedBitVector::alloc()
{
uint32_t words = capacityWords();
words += (-words & 15); // Pad to 64 byte alignment
const size_t sz(words * sizeof(Word));
- DefaultAlloc::create(sz).swap(_alloc);
+ Alloc::alloc(sz).swap(_alloc);
assert(_alloc.size()/sizeof(Word) >= words);
// Clear padding
memset(static_cast<char *>(_alloc.get()) + sizeBytes(), 0, sz - sizeBytes());
diff --git a/searchlib/src/vespa/searchlib/common/bitvector.cpp b/searchlib/src/vespa/searchlib/common/bitvector.cpp
index 441351ab724..4f04a557085 100644
--- a/searchlib/src/vespa/searchlib/common/bitvector.cpp
+++ b/searchlib/src/vespa/searchlib/common/bitvector.cpp
@@ -14,7 +14,7 @@ using vespalib::make_string;
using vespalib::IllegalArgumentException;
using vespalib::hwaccelrated::IAccelrated;
using vespalib::Optimized;
-using vespalib::DefaultAlloc;
+using vespalib::alloc::Alloc;
namespace {
@@ -323,7 +323,7 @@ BitVector::create(Index numberOfElements,
size_t vectorsize = getFileBytes(numberOfElements);
file.DirectIOPadding(offset, vectorsize, padbefore, padafter);
assert((padbefore & (getAlignment() - 1)) == 0);
- AllocatedBitVector::Alloc alloc = DefaultAlloc::create(padbefore + vectorsize + padafter, 0x1000000, 0x1000);
+ AllocatedBitVector::Alloc alloc = Alloc::alloc(padbefore + vectorsize + padafter, 0x1000000, 0x1000);
void * alignedBuffer = alloc.get();
file.ReadBuf(alignedBuffer, alloc.size(), offset - padbefore);
bv.reset(new AllocatedBitVector(numberOfElements, std::move(alloc), padbefore));
diff --git a/searchlib/src/vespa/searchlib/common/partialbitvector.cpp b/searchlib/src/vespa/searchlib/common/partialbitvector.cpp
index 59130ac7ec9..ba165421a41 100644
--- a/searchlib/src/vespa/searchlib/common/partialbitvector.cpp
+++ b/searchlib/src/vespa/searchlib/common/partialbitvector.cpp
@@ -5,13 +5,13 @@
#include <vespa/fastos/fastos.h>
#include "partialbitvector.h"
-using vespalib::DefaultAlloc;
-
namespace search {
+using vespalib::alloc::Alloc;
+
PartialBitVector::PartialBitVector(Index start, Index end) :
BitVector(),
- _alloc(DefaultAlloc::create(numActiveBytes(start, end), 0x1000000, 0x1000))
+ _alloc(Alloc::alloc(numActiveBytes(start, end), 0x1000000, 0x1000))
{
init(_alloc.get(), start, end);
clear();
diff --git a/searchlib/src/vespa/searchlib/common/resultset.cpp b/searchlib/src/vespa/searchlib/common/resultset.cpp
index cdbfebdc1a9..0544e54b59b 100644
--- a/searchlib/src/vespa/searchlib/common/resultset.cpp
+++ b/searchlib/src/vespa/searchlib/common/resultset.cpp
@@ -6,7 +6,6 @@
#include <vespa/searchlib/common/resultset.h>
#include <vespa/searchlib/common/bitvector.h>
-using vespalib::DefaultAlloc;
using vespalib::alloc::Alloc;
namespace search {
@@ -51,7 +50,7 @@ void
ResultSet::allocArray(unsigned int arrayAllocated)
{
if (arrayAllocated > 0) {
- DefaultAlloc::create(arrayAllocated * sizeof(RankedHit), MMAP_LIMIT).swap(_rankedHitsArray);
+ Alloc::alloc(arrayAllocated * sizeof(RankedHit), MMAP_LIMIT).swap(_rankedHitsArray);
} else {
Alloc().swap(_rankedHitsArray);
}
@@ -99,7 +98,7 @@ ResultSet::mergeWithBitOverflow(void)
uint32_t bidx = bitVector->getFirstTrueBit();
uint32_t actualHits = getNumHits();
- Alloc newHitsAlloc = DefaultAlloc::create(actualHits*sizeof(RankedHit), MMAP_LIMIT);
+ Alloc newHitsAlloc = Alloc::alloc(actualHits*sizeof(RankedHit), MMAP_LIMIT);
RankedHit *newHitsArray = static_cast<RankedHit *>(newHitsAlloc.get());
RankedHit * tgtA = newHitsArray;
diff --git a/searchlib/src/vespa/searchlib/common/sortresults.cpp b/searchlib/src/vespa/searchlib/common/sortresults.cpp
index 76109f3ec42..0b430369e96 100644
--- a/searchlib/src/vespa/searchlib/common/sortresults.cpp
+++ b/searchlib/src/vespa/searchlib/common/sortresults.cpp
@@ -16,9 +16,7 @@ using search::common::SortSpec;
using search::common::SortInfo;
using search::attribute::IAttributeContext;
using search::attribute::IAttributeVector;
-
-using vespalib::DefaultAlloc;
-
+using vespalib::alloc::Alloc;
namespace {
constexpr size_t MMAP_LIMIT = 0x2000000;
@@ -29,8 +27,7 @@ class RadixHelper
public:
typedef vespalib::convertForSort<T, true> C;
inline typename C::UIntType
- operator()(typename C::InputType v) const
- {
+ operator()(typename C::InputType v) const {
return C::convert(v);
}
};
@@ -46,12 +43,10 @@ FastS_insertion_sort(RankedHit a[], uint32_t n)
typedef RadixHelper<search::HitRank> RT;
RT R;
- for (i=1; i<n ; i++)
- {
+ for (i=1; i<n ; i++) {
swap = a[i];
j = i;
- while (R(swap._rankValue) > R(a[j-1]._rankValue))
- {
+ while (R(swap._rankValue) > R(a[j-1]._rankValue)) {
a[j] = a[j-1];
if (!(--j)) break;;
}
@@ -87,24 +82,20 @@ FastS_radixsort(RankedHit a[], uint32_t n, uint32_t ntop)
sorted = (cnt[0]==n);
ptr[0] = n-cnt[0];
last[0] = n;
- for(i=1; i<256; i++)
- {
+ for(i=1; i<256; i++) {
ptr[i] = (last[i]=ptr[i-1]) - cnt[i];
sorted |= (cnt[i]==n);
}
- if (!sorted)
- {
+ if (!sorted) {
// Go through all permutation cycles until all
// elements are moved or found to be already in place
i = 255;
remain = n;
- while(remain>0)
- {
+ while(remain>0) {
// Find first uncompleted class
- while(ptr[i]==last[i])
- {
+ while(ptr[i]==last[i]) {
i--;
}
@@ -117,10 +108,8 @@ FastS_radixsort(RankedHit a[], uint32_t n, uint32_t ntop)
k = (R(swap._rankValue) >> SHIFT) & 0xFF;
// Swap into correct class until cycle completed
- if (i!=k)
- {
- do
- {
+ if (i!=k) {
+ do {
temp = a[ptr[k]];
a[ptr[k]++] = swap;
k = (R((swap = temp)._rankValue) >> SHIFT) & 0xFF;
@@ -137,10 +126,9 @@ FastS_radixsort(RankedHit a[], uint32_t n, uint32_t ntop)
return;
}
- if (SHIFT>0)
- {
+ if (SHIFT>0) {
// Sort on next key
- for(i=0; i<256 ; i++)
+ for(i=0; i<256 ; i++) {
if ((last[i]-cnt[i])<ntop) {
if (cnt[i]>INSERT_SORT_LEVEL) {
if (last[i]<ntop) {
@@ -153,6 +141,7 @@ FastS_radixsort(RankedHit a[], uint32_t n, uint32_t ntop)
} else if (cnt[i]>1) {
FastS_insertion_sort(&a[last[i]-cnt[i]], cnt[i]);
}
+ }
}
}
}
@@ -428,12 +417,10 @@ FastS_insertion_sort(T a[], uint32_t n, Compare *compobj)
uint32_t i, j;
T swap;
- for (i=1; i<n ; i++)
- {
+ for (i=1; i<n ; i++) {
swap = a[i];
j = i;
- while (Compare::Compare(compobj, swap, a[j-1]) < 0)
- {
+ while (Compare::Compare(compobj, swap, a[j-1]) < 0) {
a[j] = a[j-1];
if (!(--j)) break;;
}
@@ -502,7 +489,7 @@ FastS_SortSpec::sortResults(RankedHit a[], uint32_t n, uint32_t topn)
} else if (_method == 1) {
std::sort(sortData, sortData + n, StdSortDataCompare(&_binarySortData[0]));
} else {
- vespalib::Array<uint32_t> radixScratchPad(n, DefaultAlloc::create(0, MMAP_LIMIT));
+ vespalib::Array<uint32_t> radixScratchPad(n, Alloc::alloc(0, MMAP_LIMIT));
search::radix_sort(SortDataRadix(&_binarySortData[0]), StdSortDataCompare(&_binarySortData[0]), SortDataEof(), 1, sortData, n, &radixScratchPad[0], 0, 96, topn);
}
for (uint32_t i(0), m(_sortDataArray.size()); i < m; ++i) {
diff --git a/searchlib/src/vespa/searchlib/docstore/compacter.cpp b/searchlib/src/vespa/searchlib/docstore/compacter.cpp
index d787f934efc..44032a1a73d 100644
--- a/searchlib/src/vespa/searchlib/docstore/compacter.cpp
+++ b/searchlib/src/vespa/searchlib/docstore/compacter.cpp
@@ -9,6 +9,8 @@ LOG_SETUP(".searchlib.docstore.compacter");
namespace search {
namespace docstore {
+using vespalib::alloc::Alloc;
+
void
Compacter::write(LockGuard guard, uint32_t chunkId, uint32_t lid, const void *buffer, size_t sz) {
(void) chunkId;
@@ -24,7 +26,7 @@ BucketCompacter::BucketCompacter(size_t maxSignificantBucketBits, const Compress
_bucketizer(bucketizer),
_writeCount(0),
_lock(),
- _backingMemory(vespalib::DefaultAlloc::create(0x40000000), &_lock),
+ _backingMemory(Alloc::alloc(0x40000000), &_lock),
_tmpStore(),
_lidGuard(ds.getLidReadGuard()),
_bucketizerGuard(bucketizer.getGuard()),
diff --git a/searchlib/src/vespa/searchlib/docstore/documentstore.h b/searchlib/src/vespa/searchlib/docstore/documentstore.h
index 7ca3b98d525..43006b18e90 100644
--- a/searchlib/src/vespa/searchlib/docstore/documentstore.h
+++ b/searchlib/src/vespa/searchlib/docstore/documentstore.h
@@ -159,6 +159,7 @@ private:
class WrapVisitorProgress;
class Value {
public:
+ using Alloc = vespalib::alloc::Alloc;
typedef std::unique_ptr<Value> UP;
Value() : _compressedSize(0), _uncompressedSize(0), _compression(document::CompressionConfig::NONE) { }
@@ -173,7 +174,7 @@ private:
_compressedSize(rhs._compressedSize),
_uncompressedSize(rhs._uncompressedSize),
_compression(rhs._compression),
- _buf(vespalib::DefaultAlloc::create(rhs.size()))
+ _buf(Alloc::alloc(rhs.size()))
{
memcpy(get(), rhs.get(), size());
}
@@ -213,7 +214,7 @@ private:
size_t _compressedSize;
size_t _uncompressedSize;
document::CompressionConfig::Type _compression;
- vespalib::alloc::Alloc _buf;
+ Alloc _buf;
};
class BackingStore {
public:
diff --git a/searchlib/src/vespa/searchlib/docstore/visitcache.cpp b/searchlib/src/vespa/searchlib/docstore/visitcache.cpp
index 89bfb2bfae4..2f957410bb9 100644
--- a/searchlib/src/vespa/searchlib/docstore/visitcache.cpp
+++ b/searchlib/src/vespa/searchlib/docstore/visitcache.cpp
@@ -10,7 +10,6 @@ using vespalib::LockGuard;
using vespalib::DataBuffer;
using vespalib::alloc::Alloc;
using vespalib::alloc::MemoryAllocator;
-using vespalib::DefaultAlloc;
KeySet::KeySet(uint32_t key) :
_keys()
@@ -31,7 +30,7 @@ KeySet::contains(const KeySet &rhs) const {
BlobSet::BlobSet() :
_positions(),
- _buffer(DefaultAlloc::create(0, 16 * MemoryAllocator::HUGEPAGE_SIZE), 0)
+ _buffer(Alloc::alloc(0, 16 * MemoryAllocator::HUGEPAGE_SIZE), 0)
{ }
namespace {
@@ -92,7 +91,7 @@ BlobSet
CompressedBlobSet::getBlobSet() const
{
// These are frequent lage allocations that are to expensive to mmap.
- DataBuffer uncompressed(0, 1, DefaultAlloc::create(0, 16 * MemoryAllocator::HUGEPAGE_SIZE));
+ DataBuffer uncompressed(0, 1, Alloc::alloc(0, 16 * MemoryAllocator::HUGEPAGE_SIZE));
if ( ! _positions.empty() ) {
document::decompress(_compression, getBufferSize(_positions), ConstBufferRef(_buffer.c_str(), _buffer.size()), uncompressed, false);
}
diff --git a/searchlib/src/vespa/searchlib/grouping/sketch.h b/searchlib/src/vespa/searchlib/grouping/sketch.h
index e336955f337..b97da00f4cf 100644
--- a/searchlib/src/vespa/searchlib/grouping/sketch.h
+++ b/searchlib/src/vespa/searchlib/grouping/sketch.h
@@ -233,7 +233,7 @@ decompress_buckets_from(char *buffer, uint32_t size) {
template <int BucketBits, typename HashT>
void NormalSketch<BucketBits, HashT>::
serialize(vespalib::Serializer &os) const {
- vespalib::alloc::Alloc backing(vespalib::DefaultAlloc::create(LZ4_compressBound(BUCKET_COUNT)));
+ vespalib::alloc::Alloc backing(vespalib::alloc::Alloc::alloc(LZ4_compressBound(BUCKET_COUNT)));
char * compress_array(static_cast<char *>(backing.get()));
uint32_t size = compress_buckets_into(compress_array, backing.size());
os << BUCKET_COUNT << size;
diff --git a/searchlib/src/vespa/searchlib/queryeval/predicate_blueprint.cpp b/searchlib/src/vespa/searchlib/queryeval/predicate_blueprint.cpp
index 1610267c255..6ad7766441a 100644
--- a/searchlib/src/vespa/searchlib/queryeval/predicate_blueprint.cpp
+++ b/searchlib/src/vespa/searchlib/queryeval/predicate_blueprint.cpp
@@ -250,7 +250,7 @@ void PredicateBlueprint::fetchPostings(bool) {
}
PredicateAttribute::MinFeatureHandle mfh = predicate_attribute().getMinFeatureVector();
- vespalib::alloc::Alloc kv(vespalib::DefaultAlloc::create(mfh.second));
+ Alloc kv(Alloc::alloc(mfh.second));
_kVBacking.swap(kv);
_kV = BitVectorCache::CountVector(static_cast<uint8_t *>(_kVBacking.get()), mfh.second);
_index.computeCountVector(_cachedFeatures, _kV);
diff --git a/searchlib/src/vespa/searchlib/queryeval/predicate_blueprint.h b/searchlib/src/vespa/searchlib/queryeval/predicate_blueprint.h
index 616460f9e55..140ee17fc62 100644
--- a/searchlib/src/vespa/searchlib/queryeval/predicate_blueprint.h
+++ b/searchlib/src/vespa/searchlib/queryeval/predicate_blueprint.h
@@ -58,6 +58,7 @@ private:
using VectorIterator = predicate::SimpleIndex<btree::EntryRef>::VectorIterator;
template <typename T>
using optional = std::experimental::optional<T>;
+ using Alloc = vespalib::alloc::Alloc;
const PredicateAttribute & predicate_attribute() const {
return _attribute;
@@ -72,7 +73,7 @@ private:
const PredicateAttribute & _attribute;
const predicate::PredicateIndex &_index;
- vespalib::alloc::Alloc _kVBacking;
+ Alloc _kVBacking;
BitVectorCache::CountVector _kV;
BitVectorCache::KeySet _cachedFeatures;
diff --git a/searchlib/src/vespa/searchlib/transactionlog/domainpart.cpp b/searchlib/src/vespa/searchlib/transactionlog/domainpart.cpp
index 776924a8c85..edec458c3b9 100644
--- a/searchlib/src/vespa/searchlib/transactionlog/domainpart.cpp
+++ b/searchlib/src/vespa/searchlib/transactionlog/domainpart.cpp
@@ -21,18 +21,16 @@ using vespalib::getLastErrorString;
using vespalib::IllegalHeaderException;
using vespalib::LockGuard;
using vespalib::nbostream;
+using vespalib::alloc::Alloc;
using search::common::FileHeaderContext;
using std::runtime_error;
-namespace search
-{
+namespace search {
-namespace transactionlog
-{
+namespace transactionlog {
+namespace {
-namespace
-{
void
handleSync(FastOS_FileInterface &file) __attribute__ ((noinline));
@@ -221,7 +219,7 @@ DomainPart::buildPacketMapping(bool allowTruncate)
SerialNum lastSerial(0);
int64_t firstPos(currPos);
bool full(false);
- vespalib::alloc::Alloc buf;
+ Alloc buf;
for(size_t i(0); !full && (currPos < fSize); i++) {
Packet::Entry e;
if (read(transLog, e, buf, allowTruncate)) {
@@ -552,7 +550,7 @@ DomainPart::visit(FastOS_FileInterface &file, SerialNumRange &r, Packet &packet)
}
if (retval) {
Packet newPacket;
- vespalib::alloc::Alloc buf;
+ Alloc buf;
for (bool full(false);!full && retval && (r.from() < r.to());) {
Packet::Entry e;
int64_t fPos = file.GetPosition();
@@ -612,7 +610,7 @@ DomainPart::write(FastOS_FileInterface &file, const Packet::Entry &entry)
bool
DomainPart::read(FastOS_FileInterface &file,
Packet::Entry &entry,
- vespalib::alloc::Alloc & buf,
+ Alloc & buf,
bool allowTruncate)
{
bool retval(true);
@@ -625,7 +623,7 @@ DomainPart::read(FastOS_FileInterface &file,
his >> version >> len;
if ((retval = (rlen == sizeof(tmp)))) {
if ( ! (retval = (version == ccitt_crc32) || version == xxh64)) {
- vespalib::string msg(make_string("Version mismatch. Expected 'ccitt_crc32=1' or 'xxh64=2',"
+ string msg(make_string("Version mismatch. Expected 'ccitt_crc32=1' or 'xxh64=2',"
" got %d from '%s' at position %ld",
version, file.GetFileName(), lastKnownGoodPos));
if ((version == 0) && (len == 0) && tailOfFileIsZero(file, lastKnownGoodPos)) {
@@ -636,7 +634,7 @@ DomainPart::read(FastOS_FileInterface &file,
}
}
if (len > buf.size()) {
- vespalib::DefaultAlloc::create(len).swap(buf);
+ Alloc::alloc(len).swap(buf);
}
rlen = file.Read(buf.get(), len);
retval = rlen == len;
diff --git a/staging_vespalib/src/tests/memorydatastore/memorydatastore.cpp b/staging_vespalib/src/tests/memorydatastore/memorydatastore.cpp
index 57a18fc5573..7c985afa6a5 100644
--- a/staging_vespalib/src/tests/memorydatastore/memorydatastore.cpp
+++ b/staging_vespalib/src/tests/memorydatastore/memorydatastore.cpp
@@ -21,7 +21,7 @@ public:
void
MemoryDataStoreTest::testMemoryDataStore()
{
- MemoryDataStore s(DefaultAlloc::create(256));
+ MemoryDataStore s(Alloc::alloc(256));
std::vector<MemoryDataStore::Reference> v;
v.push_back(s.push_back("mumbo", 5));
for (size_t i(0); i < 50; i++) {
diff --git a/staging_vespalib/src/vespa/vespalib/data/databuffer.h b/staging_vespalib/src/vespa/vespalib/data/databuffer.h
index 53e9e54d0f5..a9ed53e2f84 100644
--- a/staging_vespalib/src/vespa/vespalib/data/databuffer.h
+++ b/staging_vespalib/src/vespa/vespalib/data/databuffer.h
@@ -33,7 +33,7 @@ namespace vespalib {
class DataBuffer
{
private:
- using Alloc = vespalib::alloc::Alloc;
+ using Alloc = alloc::Alloc;
size_t _alignment;
char *_externalBuf;
char *_bufstart;
@@ -53,7 +53,7 @@ public:
* @param len the initial size of the buffer.
* @param alignment required memory alignment for data start
**/
- DataBuffer(size_t len = 1024, size_t alignment = 1, const Alloc & initial = vespalib::DefaultAlloc::create(0));
+ DataBuffer(size_t len = 1024, size_t alignment = 1, const Alloc & initial = Alloc::alloc(0));
/**
* Construct a databuffer using externally allocated memory. Note
@@ -70,7 +70,7 @@ public:
_bufend(buf + len),
_datapt(_bufstart),
_freept(_bufstart),
- _buffer(vespalib::DefaultAlloc::create(0))
+ _buffer(Alloc::alloc(0))
{ }
DataBuffer(const char *buf, size_t len) :
@@ -80,7 +80,7 @@ public:
_bufend(_bufstart + len),
_datapt(_bufstart),
_freept(_bufend),
- _buffer(vespalib::DefaultAlloc::create(0))
+ _buffer(Alloc::alloc(0))
{ }
/**
diff --git a/staging_vespalib/src/vespa/vespalib/util/growablebytebuffer.cpp b/staging_vespalib/src/vespa/vespalib/util/growablebytebuffer.cpp
index b17accddc5d..abd5e7a2b5b 100644
--- a/staging_vespalib/src/vespa/vespalib/util/growablebytebuffer.cpp
+++ b/staging_vespalib/src/vespa/vespalib/util/growablebytebuffer.cpp
@@ -5,7 +5,7 @@
using namespace vespalib;
GrowableByteBuffer::GrowableByteBuffer(uint32_t initialLen) :
- _buffer(DefaultAlloc::create(initialLen)),
+ _buffer(Alloc::alloc(initialLen)),
_position(0)
{
}
@@ -16,7 +16,7 @@ GrowableByteBuffer::allocate(uint32_t len)
size_t need(_position + len);
if (need > _buffer.size()) {
uint32_t newSize = vespalib::roundUp2inN(need);
- Alloc newBuf(DefaultAlloc::create(newSize));
+ Alloc newBuf(Alloc::alloc(newSize));
memcpy(newBuf.get(), _buffer.get(), _position);
_buffer.swap(newBuf);
}
diff --git a/storageapi/src/vespa/storageapi/mbusprot/storagereply.cpp b/storageapi/src/vespa/storageapi/mbusprot/storagereply.cpp
index 0165348968e..f91893ea355 100644
--- a/storageapi/src/vespa/storageapi/mbusprot/storagereply.cpp
+++ b/storageapi/src/vespa/storageapi/mbusprot/storagereply.cpp
@@ -4,7 +4,6 @@
#include <vespa/storageapi/mbusprot/storagecommand.h>
-using vespalib::DefaultAlloc;
using vespalib::alloc::Alloc;
using vespalib::IllegalStateException;
@@ -14,7 +13,7 @@ namespace mbusprot {
StorageReply::StorageReply(const mbus::BlobRef& data,
const ProtocolSerialization& serializer)
: _serializer(&serializer),
- _buffer(DefaultAlloc::create(data.size())),
+ _buffer(Alloc::alloc(data.size())),
_mbusType(0),
_reply()
{
diff --git a/vespalib/src/tests/alloc/alloc_test.cpp b/vespalib/src/tests/alloc/alloc_test.cpp
index c0f732cf9da..8a1049f2784 100644
--- a/vespalib/src/tests/alloc/alloc_test.cpp
+++ b/vespalib/src/tests/alloc/alloc_test.cpp
@@ -48,13 +48,13 @@ void
Test::testBasic()
{
{
- Alloc h = HeapAllocFactory::create(100);
+ Alloc h = Alloc::allocHeap(100);
EXPECT_EQUAL(100u, h.size());
EXPECT_TRUE(h.get() != nullptr);
}
{
- EXPECT_EXCEPTION(AlignedHeapAllocFactory::create(100, 7), IllegalArgumentException, "AlignedHeapAllocFactory::create(100, 7) does not support 7 alignment");
- Alloc h = AlignedHeapAllocFactory::create(100, 1024);
+ EXPECT_EXCEPTION(Alloc::allocAlignedHeap(100, 7), IllegalArgumentException, "Alloc::allocAlignedHeapAlloc(100, 7) does not support 7 alignment");
+ Alloc h = Alloc::allocAlignedHeapAlloc(100, 1024);
EXPECT_EQUAL(100u, h.size());
EXPECT_TRUE(h.get() != nullptr);
}
@@ -64,7 +64,7 @@ Test::testBasic()
EXPECT_TRUE(h.get() != nullptr);
}
{
- Alloc a = HeapAllocFactory::create(100), b = HeapAllocFactory::create(200);
+ Alloc a = Alloc::allocHeap(100), b = Alloc::allocHeap(200);
testSwap(a, b);
}
{
@@ -72,17 +72,17 @@ Test::testBasic()
testSwap(a, b);
}
{
- Alloc a = AlignedHeapAllocFactory::create(100, 1024), b = AlignedHeapAllocFactory::create(200, 1024);
+ Alloc a = Alloc::allocAlignedHeap(100, 1024), b = Alloc::allocAlignedHeap(200, 1024);
testSwap(a, b);
}
{
- Alloc a = HeapAllocFactory::create(100);
+ Alloc a = Alloc::allocHeap(100);
Alloc b = MMapAllocFactory::create(200);
testSwap(a, b);
}
{
- Alloc a = HeapAllocFactory::create(100);
- Alloc b = HeapAllocFactory::create(100);
+ Alloc a = Alloc::allocHeap(100);
+ Alloc b = Alloc::allocHeap(100);
a = std::move(b);
EXPECT_TRUE(b.get() == nullptr);
}
diff --git a/vespalib/src/tests/alloc/allocate_and_core.cpp b/vespalib/src/tests/alloc/allocate_and_core.cpp
index f0a0669eb42..63718de5ee4 100644
--- a/vespalib/src/tests/alloc/allocate_and_core.cpp
+++ b/vespalib/src/tests/alloc/allocate_and_core.cpp
@@ -6,9 +6,9 @@ using namespace vespalib::alloc;
int main(int argc, char *argv[]) {
(void) argc;
(void) argv;
- Alloc small(MMapAllocFactory::create(0x400000)); //4M
+ Alloc small(Alloc::allocMMap(0x400000)); //4M
memset(small.get(), 0x55, small.size());
- Alloc large(MMapAllocFactory::create(0x4000000)); //640M
+ Alloc large(Alloc::allocMMap(0x4000000)); //640M
memset(large.get(), 0x66, large.size());
assert(false);
}
diff --git a/vespalib/src/vespa/vespalib/data/memorydatastore.cpp b/vespalib/src/vespa/vespalib/data/memorydatastore.cpp
index 791ea0cea50..824a8adf1d6 100644
--- a/vespalib/src/vespa/vespalib/data/memorydatastore.cpp
+++ b/vespalib/src/vespa/vespalib/data/memorydatastore.cpp
@@ -41,7 +41,7 @@ MemoryDataStore::push_back(const void * data, const size_t sz)
VariableSizeVector::VariableSizeVector(size_t initialSize) :
_vector(),
- _store(DefaultAlloc::create(initialSize))
+ _store(Alloc::alloc(initialSize))
{
}
diff --git a/vespalib/src/vespa/vespalib/data/memorydatastore.h b/vespalib/src/vespa/vespalib/data/memorydatastore.h
index b61fa3665ad..dd5809c1423 100644
--- a/vespalib/src/vespa/vespalib/data/memorydatastore.h
+++ b/vespalib/src/vespa/vespalib/data/memorydatastore.h
@@ -23,7 +23,7 @@ public:
private:
void * _data;
};
- MemoryDataStore(alloc::Alloc && initialAlloc=DefaultAlloc::create(256), Lock * lock=nullptr);
+ MemoryDataStore(alloc::Alloc && initialAlloc=alloc::Alloc::alloc(256), Lock * lock=nullptr);
MemoryDataStore(const MemoryDataStore &) = delete;
MemoryDataStore & operator = (const MemoryDataStore &) = delete;
~MemoryDataStore();
diff --git a/vespalib/src/vespa/vespalib/util/alloc.cpp b/vespalib/src/vespa/vespalib/util/alloc.cpp
index c1542b70eff..7b47802f8c8 100644
--- a/vespalib/src/vespa/vespalib/util/alloc.cpp
+++ b/vespalib/src/vespa/vespalib/util/alloc.cpp
@@ -356,13 +356,13 @@ AutoAllocator::free(PtrAndSize alloc) const {
}
Alloc
-HeapAllocFactory::create(size_t sz)
+Alloc::allocHeap(size_t sz)
{
return Alloc(&HeapAllocator::getDefault(), sz);
}
Alloc
-AlignedHeapAllocFactory::create(size_t sz, size_t alignment)
+Alloc::allocAlignedHeap(size_t sz, size_t alignment)
{
if (alignment == 0) {
return Alloc(&AlignedHeapAllocator::getDefault(), sz);
@@ -373,18 +373,18 @@ AlignedHeapAllocFactory::create(size_t sz, size_t alignment)
} else if (alignment == 0x1000) {
return Alloc(&AlignedHeapAllocator::get4K(), sz);
} else {
- throw IllegalArgumentException(make_string("AlignedHeapAllocFactory::create(%zu, %zu) does not support %zu alignment", sz, alignment, alignment));
+ throw IllegalArgumentException(make_string("Alloc::allocAlignedHeap::create(%zu, %zu) does not support %zu alignment", sz, alignment, alignment));
}
}
Alloc
-MMapAllocFactory::create(size_t sz)
+Alloc::allocMMap(size_t sz)
{
return Alloc(&MMapAllocator::getDefault(), sz);
}
Alloc
-AutoAllocFactory::create(size_t sz, size_t mmapLimit, size_t alignment)
+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 b8ed90c75cf..b8b2374c109 100644
--- a/vespalib/src/vespa/vespalib/util/alloc.h
+++ b/vespalib/src/vespa/vespalib/util/alloc.h
@@ -61,7 +61,6 @@ public:
return *this;
}
Alloc() : _alloc(nullptr, 0), _allocator(nullptr) { }
- Alloc(const MemoryAllocator * allocator, size_t sz) : _alloc(allocator->alloc(sz)), _allocator(allocator) { }
~Alloc() {
if (_alloc.first != nullptr) {
_allocator->free(_alloc);
@@ -75,7 +74,17 @@ public:
Alloc create(size_t sz) const {
return Alloc(_allocator, sz);
}
+
+ static Alloc allocAlignedHeap(size_t sz, size_t alignment);
+ static Alloc allocHeap(size_t sz=0);
+ static Alloc allocMMap(size_t sz=0);
+ /**
+ * 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);
private:
+ Alloc(const MemoryAllocator * allocator, size_t sz) : _alloc(allocator->alloc(sz)), _allocator(allocator) { }
void clear() {
_alloc.first = nullptr;
_alloc.second = 0;
@@ -85,42 +94,10 @@ private:
const MemoryAllocator * _allocator;
};
-class HeapAllocFactory
-{
-public:
- static Alloc create(size_t sz=0);
-};
-
-class AlignedHeapAllocFactory
-{
-public:
- static Alloc create(size_t sz, size_t alignment);
-};
-
-class MMapAllocFactory
-{
-public:
- enum {HUGEPAGE_SIZE=0x200000};
- static Alloc create(size_t sz=0);
-};
-
-/**
- * Optional alignment is assumed to be <= system page size, since mmap
- * is always used when size is above limit.
- */
-
-class AutoAllocFactory
-{
-public:
- static Alloc create(size_t sz=0, size_t mmapLimit=MemoryAllocator::HUGEPAGE_SIZE, size_t alignment=0);
-};
-
}
inline size_t roundUp2inN(size_t minimum) {
return 2ul << Optimized::msbIdx(minimum - 1);
}
-using DefaultAlloc = alloc::AutoAllocFactory;
-
}
diff --git a/vespalib/src/vespa/vespalib/util/array.h b/vespalib/src/vespa/vespalib/util/array.h
index f2546e46e22..4df60d68cdc 100644
--- a/vespalib/src/vespa/vespalib/util/array.h
+++ b/vespalib/src/vespa/vespalib/util/array.h
@@ -108,12 +108,12 @@ public:
typedef T value_type;
typedef size_t size_type;
- Array(const Alloc & initial=DefaultAlloc::create()) : _array(initial.create(0)), _sz(0) { }
- Array(size_t sz, const Alloc & initial=DefaultAlloc::create());
+ Array(const Alloc & initial=Alloc::alloc()) : _array(initial.create(0)), _sz(0) { }
+ Array(size_t sz, const Alloc & initial=Alloc::alloc());
Array(Alloc && buf, size_t sz);
Array(Array &&rhs);
- Array(size_t sz, T value, const Alloc & initial=DefaultAlloc::create());
- Array(const_iterator begin, const_iterator end, const Alloc & initial=DefaultAlloc::create());
+ Array(size_t sz, T value, const Alloc & initial=Alloc::alloc());
+ Array(const_iterator begin, const_iterator end, const Alloc & initial=Alloc::alloc());
Array(const Array & rhs);
Array & operator =(const Array & rhs) {
if (&rhs != this) {