aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2016-10-02 19:59:41 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2016-10-03 16:52:36 +0000
commit6a0ea2d5fce1967927cf1f4f319fb0209ac2eb1e (patch)
treecdf844359ac298e85d5ffc4e15f467964a8c7593
parent74d9d289d9b9ffd5f9f427a1fb7abf176bae4abe (diff)
Checkpoint 1
-rw-r--r--config/src/vespa/config/frt/protocol.cpp11
-rw-r--r--config/src/vespa/config/frt/protocol.h6
-rw-r--r--document/src/vespa/document/bucket/bucketid.h2
-rw-r--r--document/src/vespa/document/util/bytebuffer.cpp17
-rw-r--r--document/src/vespa/document/util/bytebuffer.h8
-rw-r--r--document/src/vespa/document/util/compressor.cpp37
-rw-r--r--fastlib/src/vespa/fastlib/io/bufferedfile.cpp2
-rw-r--r--fastlib/src/vespa/fastlib/io/bufferedfile.h2
-rw-r--r--fnet/src/vespa/fnet/databuffer.cpp6
-rw-r--r--fnet/src/vespa/fnet/databuffer.h11
-rw-r--r--fnet/src/vespa/fnet/frt/values.h10
-rw-r--r--memfilepersistence/src/tests/spi/buffer_test.cpp5
-rw-r--r--memfilepersistence/src/vespa/memfilepersistence/mapper/buffer.cpp11
-rw-r--r--memfilepersistence/src/vespa/memfilepersistence/mapper/buffer.h8
-rw-r--r--memfilepersistence/src/vespa/memfilepersistence/mapper/simplememfileiobuffer.h4
-rw-r--r--messagebus/src/vespa/messagebus/blob.h8
-rw-r--r--searchlib/src/vespa/searchlib/attribute/changevector.h2
-rw-r--r--searchlib/src/vespa/searchlib/attribute/enumstore.h2
-rw-r--r--searchlib/src/vespa/searchlib/attribute/enumstorebase.h4
-rw-r--r--searchlib/src/vespa/searchlib/attribute/iattributefilewriter.h2
-rw-r--r--searchlib/src/vespa/searchlib/attribute/loadedenumvalue.h2
-rw-r--r--searchlib/src/vespa/searchlib/attribute/loadednumericvalue.h33
-rw-r--r--searchlib/src/vespa/searchlib/attribute/loadedstringvalue.cpp11
-rw-r--r--searchlib/src/vespa/searchlib/attribute/loadedstringvalue.h2
-rw-r--r--searchlib/src/vespa/searchlib/attribute/multinumericenumattribute.h2
-rw-r--r--searchlib/src/vespa/searchlib/attribute/multivaluemapping.h6
-rw-r--r--searchlib/src/vespa/searchlib/attribute/postingchange.h2
-rw-r--r--searchlib/src/vespa/searchlib/attribute/postinglistattribute.cpp3
-rw-r--r--searchlib/src/vespa/searchlib/attribute/predicate_attribute.cpp4
-rw-r--r--searchlib/src/vespa/searchlib/attribute/singleenumattribute.h3
-rw-r--r--searchlib/src/vespa/searchlib/attribute/singlenumericenumattribute.h2
-rw-r--r--searchlib/src/vespa/searchlib/attribute/stringbase.h2
-rw-r--r--searchlib/src/vespa/searchlib/attribute/tensorattribute.h2
-rw-r--r--searchlib/src/vespa/searchlib/btree/btreenodeallocator.h4
-rw-r--r--searchlib/src/vespa/searchlib/btree/bufferstate.cpp21
-rw-r--r--searchlib/src/vespa/searchlib/btree/bufferstate.h236
-rw-r--r--searchlib/src/vespa/searchlib/btree/datastorebase.h2
-rw-r--r--searchlib/src/vespa/searchlib/common/allocatedbitvector.cpp2
-rw-r--r--searchlib/src/vespa/searchlib/common/allocatedbitvector.h3
-rw-r--r--searchlib/src/vespa/searchlib/common/rcuvector.h2
-rw-r--r--searchlib/src/vespa/searchlib/diskindex/docidmapper.h2
-rw-r--r--searchlib/src/vespa/searchlib/diskindex/indexbuilder.cpp6
-rw-r--r--searchlib/src/vespa/searchlib/diskindex/wordnummapper.h2
-rw-r--r--searchlib/src/vespa/searchlib/docstore/documentstore.h4
-rw-r--r--searchlib/src/vespa/searchlib/docstore/filechunk.cpp2
-rw-r--r--searchlib/src/vespa/searchlib/docstore/filechunk.h2
-rw-r--r--searchlib/src/vespa/searchlib/docstore/storebybucket.h2
-rw-r--r--searchlib/src/vespa/searchlib/docstore/visitcache.cpp2
-rw-r--r--searchlib/src/vespa/searchlib/docstore/visitcache.h2
-rw-r--r--searchlib/src/vespa/searchlib/engine/searchreply.h2
-rw-r--r--searchlib/src/vespa/searchlib/grouping/sketch.h11
-rw-r--r--searchlib/src/vespa/searchlib/memoryindex/fieldinverter.h2
-rw-r--r--searchlib/src/vespa/searchlib/memoryindex/memoryfieldindex.cpp2
-rw-r--r--searchlib/src/vespa/searchlib/predicate/document_features_store.h4
-rw-r--r--searchlib/src/vespa/searchlib/predicate/predicate_index.cpp10
-rw-r--r--searchlib/src/vespa/searchlib/predicate/predicate_index.h4
-rw-r--r--searchlib/src/vespa/searchlib/predicate/predicate_interval.h8
-rw-r--r--searchlib/src/vespa/searchlib/predicate/simple_index.h8
-rw-r--r--searchlib/src/vespa/searchlib/queryeval/predicate_blueprint.cpp2
-rw-r--r--searchlib/src/vespa/searchlib/queryeval/predicate_blueprint.h2
-rw-r--r--searchlib/src/vespa/searchlib/util/fileutil.h6
-rw-r--r--staging_vespalib/src/tests/array/allocinarray_benchmark.cpp2
-rw-r--r--staging_vespalib/src/tests/array/allocinarray_test.cpp2
-rw-r--r--staging_vespalib/src/vespa/vespalib/data/databuffer.cpp48
-rw-r--r--staging_vespalib/src/vespa/vespalib/data/databuffer.h33
-rw-r--r--staging_vespalib/src/vespa/vespalib/util/allocinarray.h2
-rw-r--r--staging_vespalib/src/vespa/vespalib/util/growablebytebuffer.cpp4
-rw-r--r--staging_vespalib/src/vespa/vespalib/util/growablebytebuffer.h4
-rw-r--r--storage/src/vespa/storage/bucketdb/judymultimap.h8
-rw-r--r--storageapi/src/vespa/storageapi/mbusprot/storagereply.cpp16
-rw-r--r--storageapi/src/vespa/storageapi/mbusprot/storagereply.h2
-rw-r--r--storageapi/src/vespa/storageapi/message/bucket.h2
-rw-r--r--vespalib/src/tests/alloc/allocate_and_core.cpp6
-rw-r--r--vespalib/src/vespa/vespalib/data/memorydatastore.cpp10
-rw-r--r--vespalib/src/vespa/vespalib/data/memorydatastore.h4
-rw-r--r--vespalib/src/vespa/vespalib/objects/nbostream.h5
-rw-r--r--vespalib/src/vespa/vespalib/stllike/hashtable.h2
-rw-r--r--vespalib/src/vespa/vespalib/util/alloc.cpp61
-rw-r--r--vespalib/src/vespa/vespalib/util/alloc.h189
-rw-r--r--vespalib/src/vespa/vespalib/util/array.h72
-rw-r--r--vsm/src/vespa/vsm/searcher/fieldsearcher.h2
81 files changed, 428 insertions, 633 deletions
diff --git a/config/src/vespa/config/frt/protocol.cpp b/config/src/vespa/config/frt/protocol.cpp
index be02bc59862..5c7af53d2af 100644
--- a/config/src/vespa/config/frt/protocol.cpp
+++ b/config/src/vespa/config/frt/protocol.cpp
@@ -6,6 +6,7 @@ LOG_SETUP(".config.frt.protocol");
#include <vespa/vespalib/util/stringfmt.h>
using namespace vespalib;
+using vespalib::alloc::Alloc;
using namespace vespalib::slime;
namespace config {
@@ -58,15 +59,15 @@ const Memory RESPONSE_COMPRESSION_INFO_UNCOMPRESSED_SIZE = "uncompressedSize";
DecompressedData
decompress_lz4(const char * input, uint32_t inputLen, int uncompressedLength)
{
- DefaultAlloc::UP memory(new DefaultAlloc(uncompressedLength));
- int sz = LZ4_decompress_safe(input, static_cast<char *>(memory->get()), inputLen, uncompressedLength);
+ Alloc memory( DefaultAlloc::create(uncompressedLength));
+ int sz = LZ4_decompress_safe(input, static_cast<char *>(memory.get()), inputLen, uncompressedLength);
if (sz >= 0 && sz != uncompressedLength) {
if (LOG_WOULD_LOG(debug)) {
LOG(debug, "Returned compressed size (%d) is not the same as uncompressed size(%d)", sz, uncompressedLength);
}
- DefaultAlloc * copy = new DefaultAlloc(sz);
- memcpy(copy->get(), memory->get(), sz);
- memory.reset(copy);
+ Alloc copy = memory.create(sz);
+ memcpy(copy.get(), memory.get(), sz);
+ memory = std::move(copy);
}
assert(sz >= 0);
return DecompressedData(std::move(memory), static_cast<uint32_t>(sz));
diff --git a/config/src/vespa/config/frt/protocol.h b/config/src/vespa/config/frt/protocol.h
index 79d916bf3e7..6d1c2b8226c 100644
--- a/config/src/vespa/config/frt/protocol.h
+++ b/config/src/vespa/config/frt/protocol.h
@@ -59,9 +59,9 @@ extern const vespalib::slime::Memory RESPONSE_COMPRESSION_INFO_TYPE;
extern const vespalib::slime::Memory RESPONSE_COMPRESSION_INFO_UNCOMPRESSED_SIZE;
struct DecompressedData {
- DecompressedData(vespalib::DefaultAlloc::UP mem, uint32_t sz)
+ DecompressedData(vespalib::alloc::Alloc mem, uint32_t sz)
: memory(std::move(mem)),
- memRef(static_cast<const char *>(memory->get()), sz),
+ memRef(static_cast<const char *>(memory.get()), sz),
size(sz)
{ }
DecompressedData(const vespalib::slime::Memory & mem, uint32_t sz)
@@ -70,7 +70,7 @@ struct DecompressedData {
size(sz)
{}
- vespalib::DefaultAlloc::UP memory;
+ vespalib::alloc::Alloc memory;
vespalib::slime::Memory memRef;
uint32_t size;
};
diff --git a/document/src/vespa/document/bucket/bucketid.h b/document/src/vespa/document/bucket/bucketid.h
index f4ec15ff7c1..15d02958746 100644
--- a/document/src/vespa/document/bucket/bucketid.h
+++ b/document/src/vespa/document/bucket/bucketid.h
@@ -50,7 +50,7 @@ public:
* typedef when needed we can alter this later with less code changes.
*/
typedef uint64_t Type;
- typedef vespalib::Array<BucketId, vespalib::DefaultAlloc> List;
+ typedef vespalib::Array<BucketId> List;
/** Create an initially unset bucket id. */
BucketId() : _id(0) {}
/** Create a bucket id with the given raw unchecked content. */
diff --git a/document/src/vespa/document/util/bytebuffer.cpp b/document/src/vespa/document/util/bytebuffer.cpp
index 070d52ef8d9..4c8116482d5 100644
--- a/document/src/vespa/document/util/bytebuffer.cpp
+++ b/document/src/vespa/document/util/bytebuffer.cpp
@@ -21,6 +21,7 @@
#define LOG_DEBUG3(a,b,c) LOG_DEBUG1(vespalib::make_string(a,b,c));
#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 {
@@ -59,7 +60,7 @@ ByteBuffer::ByteBuffer() :
}
ByteBuffer::ByteBuffer(size_t len) :
- ByteBuffer(DefaultAlloc(len), len)
+ ByteBuffer(DefaultAlloc::create(len), len)
{
}
@@ -74,7 +75,7 @@ ByteBuffer::ByteBuffer(const char* buffer, size_t len) :
set(buffer, len);
}
-ByteBuffer::ByteBuffer(DefaultAlloc buffer, size_t len) :
+ByteBuffer::ByteBuffer(Alloc buffer, size_t len) :
_buffer(static_cast<char *>(buffer.get())),
_len(len),
_pos(0),
@@ -114,7 +115,7 @@ ByteBuffer& ByteBuffer::operator=(const ByteBuffer & org)
if (this != & org) {
cleanUp();
if (org._len > 0 && org._buffer) {
- DefaultAlloc(org._len + 1).swap(_ownedBuffer);
+ DefaultAlloc::create(org._len + 1).swap(_ownedBuffer);
_buffer = static_cast<char *>(_ownedBuffer.get());
memcpy(_buffer,org._buffer,org._len);
_buffer[org._len] = 0;
@@ -189,7 +190,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(to-from + 1).swap(_ownedBuffer);
+ DefaultAlloc::create(to-from + 1).swap(_ownedBuffer);
_buffer = static_cast<char *>(_ownedBuffer.get());
memcpy(_buffer, buf._buffer + from, to-from);
_buffer[to-from] = 0;
@@ -200,7 +201,7 @@ ByteBuffer::sliceFrom(const ByteBuffer& buf, size_t from, size_t to) // throw (B
// Slicing from someone that owns, but hasn't made a reference counter yet.
if (!buf._bufHolder) {
- buf._bufHolder=new BufferHolder(std::move(const_cast<DefaultAlloc &>(buf._ownedBuffer)));
+ buf._bufHolder=new BufferHolder(std::move(const_cast<Alloc &>(buf._ownedBuffer)));
}
// Slicing from refcounter.
@@ -218,7 +219,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) {
- DefaultAlloc newBuf(len + 1);
+ Alloc newBuf = DefaultAlloc::create(len + 1);
memcpy(newBuf.get(), buffer, len);
static_cast<char *>(newBuf.get())[len] = 0;
return new ByteBuffer(std::move(newBuf), len);
@@ -265,7 +266,7 @@ void ByteBuffer::flip()
}
-ByteBuffer::BufferHolder::BufferHolder(DefaultAlloc buffer)
+ByteBuffer::BufferHolder::BufferHolder(Alloc buffer)
: _buffer(std::move(buffer))
{
}
@@ -753,7 +754,7 @@ void ByteBuffer::cleanUp() {
_bufHolder->subRef();
_bufHolder = NULL;
} else {
- DefaultAlloc().swap(_ownedBuffer);
+ Alloc().swap(_ownedBuffer);
}
_buffer = NULL;
}
diff --git a/document/src/vespa/document/util/bytebuffer.h b/document/src/vespa/document/util/bytebuffer.h
index cfb72e092a5..9207d47350d 100644
--- a/document/src/vespa/document/util/bytebuffer.h
+++ b/document/src/vespa/document/util/bytebuffer.h
@@ -73,7 +73,7 @@ public:
* @param buffer The buffer to represent.
* @param len The length of the buffer
*/
- ByteBuffer(vespalib::DefaultAlloc buffer, size_t len);
+ ByteBuffer(vespalib::alloc::Alloc buffer, size_t len);
/**
* Sets the buffer pointed to by this buffer. Allows for multiple
@@ -393,10 +393,10 @@ public:
BufferHolder& operator=(const BufferHolder &);
public:
- BufferHolder(vespalib::DefaultAlloc buffer);
+ BufferHolder(vespalib::alloc::Alloc buffer);
virtual ~BufferHolder();
- vespalib::DefaultAlloc _buffer;
+ vespalib::alloc::Alloc _buffer;
};
ByteBuffer(BufferHolder* buf, size_t pos, size_t len, size_t limit);
@@ -409,7 +409,7 @@ private:
size_t _pos;
size_t _limit;
mutable BufferHolder * _bufHolder;
- vespalib::DefaultAlloc _ownedBuffer;
+ vespalib::alloc::Alloc _ownedBuffer;
public:
std::string toString();
diff --git a/document/src/vespa/document/util/compressor.cpp b/document/src/vespa/document/util/compressor.cpp
index f11283c7c40..9f0c6913325 100644
--- a/document/src/vespa/document/util/compressor.cpp
+++ b/document/src/vespa/document/util/compressor.cpp
@@ -11,6 +11,12 @@ LOG_SETUP(".document.compressor");
#include <lz4.h>
#include <lz4hc.h>
+using vespalib::alloc::Alloc;
+using vespalib::DefaultAlloc;
+using vespalib::ConstBufferRef;
+using vespalib::DataBuffer;
+using vespalib::make_string;
+
namespace document
{
@@ -24,10 +30,10 @@ LZ4Compressor::process(const CompressionConfig& config, const void * inputV, siz
char * output(static_cast<char *>(outputV));
int sz(-1);
if (config.compressionLevel > 6) {
- vespalib::DefaultAlloc state(LZ4_sizeofStateHC());
+ Alloc state = DefaultAlloc::create(LZ4_sizeofStateHC());
sz = LZ4_compressHC2_withStateHC(state.get(), input, output, inputLen, config.compressionLevel);
} else {
- vespalib::DefaultAlloc state(LZ4_sizeofState());
+ Alloc state = DefaultAlloc::create(LZ4_sizeofState());
sz = LZ4_compress_withState(state.get(), input, output, inputLen);
}
if (sz != 0) {
@@ -52,7 +58,7 @@ LZ4Compressor::unprocess(const void * inputV, size_t inputLen, void * outputV, s
}
CompressionConfig::Type
-compress(ICompressor & compressor, const CompressionConfig & compression, const vespalib::ConstBufferRef & org, vespalib::DataBuffer & dest)
+compress(ICompressor & compressor, const CompressionConfig & compression, const ConstBufferRef & org, DataBuffer & dest)
{
CompressionConfig::Type type(CompressionConfig::NONE);
dest.ensureFree(compressor.adjustProcessLen(0, org.size()));
@@ -67,7 +73,7 @@ compress(ICompressor & compressor, const CompressionConfig & compression, const
}
CompressionConfig::Type
-docompress(const CompressionConfig & compression, const vespalib::ConstBufferRef & org, vespalib::DataBuffer & dest)
+docompress(const CompressionConfig & compression, const ConstBufferRef & org, DataBuffer & dest)
{
CompressionConfig::Type type(CompressionConfig::NONE);
switch (compression.type) {
@@ -85,7 +91,7 @@ docompress(const CompressionConfig & compression, const vespalib::ConstBufferRef
}
CompressionConfig::Type
-compress(const CompressionConfig & compression, const vespalib::ConstBufferRef & org, vespalib::DataBuffer & dest, bool allowSwap)
+compress(const CompressionConfig & compression, const ConstBufferRef & org, DataBuffer & dest, bool allowSwap)
{
CompressionConfig::Type type(CompressionConfig::NONE);
if (org.size() >= compression.minSize) {
@@ -93,7 +99,7 @@ compress(const CompressionConfig & compression, const vespalib::ConstBufferRef &
}
if (type == CompressionConfig::NONE) {
if (allowSwap) {
- vespalib::DataBuffer tmp(const_cast<char *>(org.c_str()), org.size());
+ DataBuffer tmp(const_cast<char *>(org.c_str()), org.size());
tmp.moveFreeToData(org.size());
dest.swap(tmp);
} else {
@@ -105,27 +111,22 @@ compress(const CompressionConfig & compression, const vespalib::ConstBufferRef &
void
-decompress(ICompressor & decompressor, size_t uncompressedLen, const vespalib::ConstBufferRef & org, vespalib::DataBuffer & dest, bool allowSwap)
+decompress(ICompressor & decompressor, size_t uncompressedLen, const ConstBufferRef & org, DataBuffer & dest, bool allowSwap)
{
dest.ensureFree(uncompressedLen);
size_t realUncompressedLen(dest.getFreeLen());
if ( ! decompressor.unprocess(org.c_str(), org.size(), dest.getFree(), realUncompressedLen) ) {
if ( uncompressedLen < realUncompressedLen) {
if (allowSwap) {
- vespalib::DataBuffer tmp(const_cast<char *>(org.c_str()), org.size());
+ DataBuffer tmp(const_cast<char *>(org.c_str()), org.size());
tmp.moveFreeToData(org.size());
dest.swap(tmp);
} else {
dest.writeBytes(org.c_str(), org.size());
}
} else {
- throw std::runtime_error(
- vespalib::make_string("unprocess failed had %" PRIu64
- ", wanted %" PRId64
- ", got %" PRIu64,
- org.size(),
- uncompressedLen,
- realUncompressedLen));
+ throw std::runtime_error(make_string("unprocess failed had %" PRIu64 ", wanted %" PRId64 ", got %" PRIu64,
+ org.size(), uncompressedLen, realUncompressedLen));
}
} else {
dest.moveFreeToData(realUncompressedLen);
@@ -133,7 +134,7 @@ decompress(ICompressor & decompressor, size_t uncompressedLen, const vespalib::C
}
void
-decompress(const CompressionConfig::Type & type, size_t uncompressedLen, const vespalib::ConstBufferRef & org, vespalib::DataBuffer & dest, bool allowSwap)
+decompress(const CompressionConfig::Type & type, size_t uncompressedLen, const ConstBufferRef & org, DataBuffer & dest, bool allowSwap)
{
switch (type) {
case CompressionConfig::LZ4:
@@ -145,7 +146,7 @@ decompress(const CompressionConfig::Type & type, size_t uncompressedLen, const v
case CompressionConfig::NONE:
case CompressionConfig::UNCOMPRESSABLE:
if (allowSwap) {
- vespalib::DataBuffer tmp(const_cast<char *>(org.c_str()), org.size());
+ DataBuffer tmp(const_cast<char *>(org.c_str()), org.size());
tmp.moveFreeToData(org.size());
dest.swap(tmp);
} else {
@@ -153,7 +154,7 @@ decompress(const CompressionConfig::Type & type, size_t uncompressedLen, const v
}
break;
default:
- throw std::runtime_error(vespalib::make_string("Unable to handle decompression of type '%d'", type));
+ throw std::runtime_error(make_string("Unable to handle decompression of type '%d'", type));
break;
}
}
diff --git a/fastlib/src/vespa/fastlib/io/bufferedfile.cpp b/fastlib/src/vespa/fastlib/io/bufferedfile.cpp
index 84eb8534cda..adf201a6e1e 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(computeBufLen(bufferSize)),
+ _buf(vespalib::alloc::MMapAllocFactory::create(computeBufLen(bufferSize))),
_bufi(NULL),
_bufe(NULL),
_filepos(0),
diff --git a/fastlib/src/vespa/fastlib/io/bufferedfile.h b/fastlib/src/vespa/fastlib/io/bufferedfile.h
index 275e066a849..7443b325dd4 100644
--- a/fastlib/src/vespa/fastlib/io/bufferedfile.h
+++ b/fastlib/src/vespa/fastlib/io/bufferedfile.h
@@ -23,7 +23,7 @@
class Fast_BufferedFile : public FastOS_FileInterface, public vespalib::noncopyable
{
private:
- typedef vespalib::MMapAlloc Alloc;
+ using Alloc = vespalib::alloc::Alloc;
/** The number of bytes left in the file. */
int64_t _fileleft;
/** Pointer to the start of the buffer. Correctly aligned for direct IO */
diff --git a/fnet/src/vespa/fnet/databuffer.cpp b/fnet/src/vespa/fnet/databuffer.cpp
index 3239dbf5087..913196d6e72 100644
--- a/fnet/src/vespa/fnet/databuffer.cpp
+++ b/fnet/src/vespa/fnet/databuffer.cpp
@@ -15,7 +15,7 @@ FNET_DataBuffer::FNET_DataBuffer(uint32_t len)
len = 256;
if (len > 0) {
- DefaultAlloc(len).swap(_ownedBuf);
+ DefaultAlloc::create(len).swap(_ownedBuf);
memset(_ownedBuf.get(), 0x55, len);
_bufstart = static_cast<char *>(_ownedBuf.get());
assert(_bufstart != NULL);
@@ -72,7 +72,7 @@ FNET_DataBuffer::Shrink(uint32_t newsize)
return false;
}
- DefaultAlloc newBuf(newsize);
+ Alloc newBuf(DefaultAlloc::create(newsize));
memset(newBuf.get(), 0x55, newsize);
memcpy(newBuf.get(), _datapt, GetDataLen());
_ownedBuf.swap(newBuf);
@@ -97,7 +97,7 @@ FNET_DataBuffer::Pack(uint32_t needbytes)
while (bufsize - GetDataLen() < needbytes)
bufsize *= 2;
- DefaultAlloc newBuf(bufsize);
+ Alloc newBuf(DefaultAlloc::create(bufsize));
memset(newBuf.get(), 0x55, bufsize);
memcpy(newBuf.get(), _datapt, GetDataLen());
_ownedBuf.swap(newBuf);
diff --git a/fnet/src/vespa/fnet/databuffer.h b/fnet/src/vespa/fnet/databuffer.h
index 23802d2ea90..8e4127d3b72 100644
--- a/fnet/src/vespa/fnet/databuffer.h
+++ b/fnet/src/vespa/fnet/databuffer.h
@@ -29,11 +29,12 @@
class FNET_DataBuffer
{
private:
- char *_bufstart;
- char *_bufend;
- char *_datapt;
- char *_freept;
- vespalib::DefaultAlloc _ownedBuf;
+ using Alloc = vespalib::alloc::Alloc;
+ char *_bufstart;
+ char *_bufend;
+ char *_datapt;
+ char *_freept;
+ Alloc _ownedBuf;
FNET_DataBuffer(const FNET_DataBuffer &);
FNET_DataBuffer &operator=(const FNET_DataBuffer &);
diff --git a/fnet/src/vespa/fnet/frt/values.h b/fnet/src/vespa/fnet/frt/values.h
index 0c3b13b16f3..8ab8914d31f 100644
--- a/fnet/src/vespa/fnet/frt/values.h
+++ b/fnet/src/vespa/fnet/frt/values.h
@@ -72,12 +72,12 @@ public:
class LocalBlob : public FRT_ISharedBlob
{
public:
- LocalBlob(vespalib::DefaultAlloc data, uint32_t len) :
+ LocalBlob(vespalib::alloc::Alloc data, uint32_t len) :
_data(std::move(data)),
_len(len)
{ }
LocalBlob(const char *data, uint32_t len) :
- _data(len),
+ _data(vespalib::DefaultAlloc::create(len)),
_len(len)
{
if (data != NULL) {
@@ -85,7 +85,7 @@ public:
}
}
void addRef() override {}
- void subRef() override { vespalib::DefaultAlloc().swap(_data); }
+ void subRef() override { vespalib::alloc::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 +93,7 @@ public:
LocalBlob(const LocalBlob &);
LocalBlob &operator=(const LocalBlob &);
- vespalib::DefaultAlloc _data;
+ vespalib::alloc::Alloc _data;
uint32_t _len;
};
@@ -439,7 +439,7 @@ public:
_typeString[_numValues++] = FRT_VALUE_DATA;
}
- void AddData(vespalib::DefaultAlloc buf, uint32_t len)
+ void AddData(vespalib::alloc::Alloc buf, uint32_t len)
{
AddSharedData(new (_tub) LocalBlob(std::move(buf), len));
}
diff --git a/memfilepersistence/src/tests/spi/buffer_test.cpp b/memfilepersistence/src/tests/spi/buffer_test.cpp
index a2d917301fc..fdbd7a32f17 100644
--- a/memfilepersistence/src/tests/spi/buffer_test.cpp
+++ b/memfilepersistence/src/tests/spi/buffer_test.cpp
@@ -36,9 +36,8 @@ BufferTest::getSizeReturnsInitiallyAllocatedSize()
void
BufferTest::getSizeReturnsUnAlignedSizeForMMappedAllocs()
{
- Buffer buf(vespalib::MMapAlloc::HUGEPAGE_SIZE + 1);
- CPPUNIT_ASSERT_EQUAL(size_t(vespalib::MMapAlloc::HUGEPAGE_SIZE + 1),
- buf.getSize());
+ Buffer buf(vespalib::alloc::MMapAllocator::HUGEPAGE_SIZE + 1);
+ CPPUNIT_ASSERT_EQUAL(size_t(vespalib::alloc::MMapAllocator::HUGEPAGE_SIZE + 1), buf.getSize());
}
void
diff --git a/memfilepersistence/src/vespa/memfilepersistence/mapper/buffer.cpp b/memfilepersistence/src/vespa/memfilepersistence/mapper/buffer.cpp
index 5ecb439b3f0..886c2a35c13 100644
--- a/memfilepersistence/src/vespa/memfilepersistence/mapper/buffer.cpp
+++ b/memfilepersistence/src/vespa/memfilepersistence/mapper/buffer.cpp
@@ -5,11 +5,18 @@
#include <algorithm>
#include <stdlib.h>
+using vespalib::DefaultAlloc;
+using vespalib::alloc::MMapAllocator;
+using vespalib::alloc::Alloc;
+
namespace storage {
namespace memfile {
+// Use AutoAlloc to transparently use mmap for large buffers.
+// 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(size),
+ : _buffer(DefaultAlloc::create(size, MMapAllocator::HUGEPAGE_SIZE, 512)),
_size(size)
{
}
@@ -17,7 +24,7 @@ Buffer::Buffer(size_t size)
void
Buffer::resize(size_t size)
{
- BackingType buffer(size);
+ Alloc buffer = _buffer.create(size);
size_t commonSize(std::min(size, _size));
memcpy(buffer.get(), _buffer.get(), commonSize);
_buffer.swap(buffer);
diff --git a/memfilepersistence/src/vespa/memfilepersistence/mapper/buffer.h b/memfilepersistence/src/vespa/memfilepersistence/mapper/buffer.h
index d097a078af9..26f4a644d0c 100644
--- a/memfilepersistence/src/vespa/memfilepersistence/mapper/buffer.h
+++ b/memfilepersistence/src/vespa/memfilepersistence/mapper/buffer.h
@@ -19,13 +19,7 @@ namespace memfile {
class Buffer
{
- // Use AutoAlloc to transparently use mmap for large buffers.
- // 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.
- static constexpr size_t MMapLimit = vespalib::MMapAlloc::HUGEPAGE_SIZE;
- using BackingType = vespalib::AutoAlloc<MMapLimit, 512>;
-
- BackingType _buffer;
+ vespalib::alloc::Alloc _buffer;
// Actual, non-aligned size (as opposed to _buffer.size()).
size_t _size;
diff --git a/memfilepersistence/src/vespa/memfilepersistence/mapper/simplememfileiobuffer.h b/memfilepersistence/src/vespa/memfilepersistence/mapper/simplememfileiobuffer.h
index 8dbffcaf795..c564893a154 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(totalSize),
+ : _buf(vespalib::alloc::MMapAllocFactory::create(totalSize)),
_usedSize(0)
{
}
@@ -115,7 +115,7 @@ public:
return static_cast<const char*>(_buf.get());
}
private:
- vespalib::MMapAlloc _buf;
+ vespalib::alloc::Alloc _buf;
size_t _usedSize;
};
diff --git a/messagebus/src/vespa/messagebus/blob.h b/messagebus/src/vespa/messagebus/blob.h
index 101ea989a92..86e317d6e79 100644
--- a/messagebus/src/vespa/messagebus/blob.h
+++ b/messagebus/src/vespa/messagebus/blob.h
@@ -22,7 +22,7 @@ public:
* @param s size of the data to be created
**/
Blob(uint32_t s) :
- _payload(s),
+ _payload(vespalib::DefaultAlloc::create(s)),
_sz(s)
{ }
Blob(Blob && rhs) :
@@ -55,11 +55,11 @@ public:
**/
const char *data() const { return static_cast<const char *>(_payload.get()); }
- vespalib::DefaultAlloc & payload() { return _payload; }
- const vespalib::DefaultAlloc & payload() const { return _payload; }
+ vespalib::alloc::Alloc & payload() { return _payload; }
+ const vespalib::alloc::Alloc & payload() const { return _payload; }
size_t size() const { return _sz; }
private:
- vespalib::DefaultAlloc _payload;
+ vespalib::alloc::Alloc _payload;
size_t _sz;
};
diff --git a/searchlib/src/vespa/searchlib/attribute/changevector.h b/searchlib/src/vespa/searchlib/attribute/changevector.h
index a714e502588..90a8ff7e2d4 100644
--- a/searchlib/src/vespa/searchlib/attribute/changevector.h
+++ b/searchlib/src/vespa/searchlib/attribute/changevector.h
@@ -140,7 +140,7 @@ template <typename T>
class ChangeVectorT : public ChangeVectorBase {
private:
typedef vespalib::hash_map<uint32_t, uint32_t> Map;
- typedef vespalib::Array<T, vespalib::DefaultAlloc> Vector;
+ typedef vespalib::Array<T> Vector;
public:
ChangeVectorT() : _tail(0) { }
class const_iterator {
diff --git a/searchlib/src/vespa/searchlib/attribute/enumstore.h b/searchlib/src/vespa/searchlib/attribute/enumstore.h
index 0f0675248a7..18bb676644e 100644
--- a/searchlib/src/vespa/searchlib/attribute/enumstore.h
+++ b/searchlib/src/vespa/searchlib/attribute/enumstore.h
@@ -154,7 +154,7 @@ public:
uint32_t _refCount;
};
- typedef vespalib::Array<UniqueEntry, vespalib::DefaultAlloc> Uniques;
+ typedef vespalib::Array<UniqueEntry> Uniques;
private:
Uniques _uniques;
uint64_t _bufferSize;
diff --git a/searchlib/src/vespa/searchlib/attribute/enumstorebase.h b/searchlib/src/vespa/searchlib/attribute/enumstorebase.h
index 3b8b9823d87..4c2d35d645f 100644
--- a/searchlib/src/vespa/searchlib/attribute/enumstorebase.h
+++ b/searchlib/src/vespa/searchlib/attribute/enumstorebase.h
@@ -34,8 +34,8 @@ class EnumStoreComparatorWrapper;
typedef btree::DataStoreT<btree::AlignedEntryRefT<31, 4> >
EnumStoreDataStoreType;
typedef EnumStoreDataStoreType::RefType EnumStoreIndex;
-typedef vespalib::Array<EnumStoreIndex, vespalib::DefaultAlloc> EnumStoreIndexVector;
-typedef vespalib::Array<uint32_t, vespalib::DefaultAlloc> EnumStoreEnumVector;
+typedef vespalib::Array<EnumStoreIndex> EnumStoreIndexVector;
+typedef vespalib::Array<uint32_t> EnumStoreEnumVector;
typedef btree::BTreeTraits<32, 32, 7, true> EnumTreeTraits;
diff --git a/searchlib/src/vespa/searchlib/attribute/iattributefilewriter.h b/searchlib/src/vespa/searchlib/attribute/iattributefilewriter.h
index ec0fbf8e6a4..d2d5cb86cf5 100644
--- a/searchlib/src/vespa/searchlib/attribute/iattributefilewriter.h
+++ b/searchlib/src/vespa/searchlib/attribute/iattributefilewriter.h
@@ -16,7 +16,7 @@ class BufferWriter;
class IAttributeFileWriter
{
public:
- using BufferBuf = vespalib::MMapDataBuffer;
+ using BufferBuf = vespalib::DataBuffer;
using Buffer = std::unique_ptr<BufferBuf>;
virtual ~IAttributeFileWriter() = default;
diff --git a/searchlib/src/vespa/searchlib/attribute/loadedenumvalue.h b/searchlib/src/vespa/searchlib/attribute/loadedenumvalue.h
index 47b7eab1b83..749247b0e78 100644
--- a/searchlib/src/vespa/searchlib/attribute/loadedenumvalue.h
+++ b/searchlib/src/vespa/searchlib/attribute/loadedenumvalue.h
@@ -94,7 +94,7 @@ public:
}
};
-typedef vespalib::Array<LoadedEnumAttribute, vespalib::DefaultAlloc> LoadedEnumAttributeVector;
+typedef vespalib::Array<LoadedEnumAttribute> LoadedEnumAttributeVector;
/**
diff --git a/searchlib/src/vespa/searchlib/attribute/loadednumericvalue.h b/searchlib/src/vespa/searchlib/attribute/loadednumericvalue.h
index a8855ba5f15..23b6f02d2fa 100644
--- a/searchlib/src/vespa/searchlib/attribute/loadednumericvalue.h
+++ b/searchlib/src/vespa/searchlib/attribute/loadednumericvalue.h
@@ -6,12 +6,9 @@
#include <vespa/searchlib/util/fileutil.h>
#include "loadedvalue.h"
+namespace search {
-namespace search
-{
-
-namespace attribute
-{
+namespace attribute {
/**
* Temporary representation of enumerated attribute loaded from non-enumerated
@@ -21,20 +18,12 @@ namespace attribute
template <typename T>
struct LoadedNumericValue : public LoadedValue<T>
{
- LoadedNumericValue()
- : LoadedValue<T>()
- {
- }
+ LoadedNumericValue() : LoadedValue<T>() { }
- class ValueCompare : public std::binary_function<LoadedNumericValue<T>,
- LoadedNumericValue<T>,
- bool>
+ class ValueCompare : public std::binary_function<LoadedNumericValue<T>, LoadedNumericValue<T>, bool>
{
public:
- bool
- operator()(const LoadedNumericValue<T> &x,
- const LoadedNumericValue<T> &y) const
- {
+ bool operator()(const LoadedNumericValue<T> &x, const LoadedNumericValue<T> &y) const {
return x < y;
}
};
@@ -42,9 +31,7 @@ struct LoadedNumericValue : public LoadedValue<T>
class ValueRadix
{
public:
- uint64_t
- operator()(const LoadedValue<T> &v) const
- {
+ uint64_t operator()(const LoadedValue<T> &v) const {
return vespalib::convertForSort<T, true>::convert(v.getValue());
}
};
@@ -53,15 +40,11 @@ struct LoadedNumericValue : public LoadedValue<T>
template <typename T>
void
-sortLoadedByValue(SequentialReadModifyWriteVector<LoadedNumericValue<T>,
- vespalib::DefaultAlloc> &
- loaded);
+sortLoadedByValue(SequentialReadModifyWriteVector<LoadedNumericValue<T>> & loaded);
template <typename T>
void
-sortLoadedByDocId(SequentialReadModifyWriteVector<LoadedNumericValue<T>,
- vespalib::DefaultAlloc> &
- loaded);
+sortLoadedByDocId(SequentialReadModifyWriteVector<LoadedNumericValue<T>> & loaded);
} // namespace attribute
diff --git a/searchlib/src/vespa/searchlib/attribute/loadedstringvalue.cpp b/searchlib/src/vespa/searchlib/attribute/loadedstringvalue.cpp
index 335abb799b0..478b7a5e7a9 100644
--- a/searchlib/src/vespa/searchlib/attribute/loadedstringvalue.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/loadedstringvalue.cpp
@@ -3,18 +3,17 @@
#include <vespa/fastos/fastos.h>
#include "loadedstringvalue.h"
+using vespalib::Array;
+using vespalib::alloc::MMapAllocFactory;
-namespace search
-{
+namespace search {
-namespace attribute
-{
+namespace attribute {
void
sortLoadedByValue(LoadedStringVectorReal &loaded)
{
- vespalib::Array<unsigned, vespalib::MMapAlloc>
- radixScratchPad(loaded.size());
+ Array<unsigned> radixScratchPad(loaded.size(), MMapAllocFactory::create());
for(size_t i(0), m(loaded.size()); i < m; i++) {
loaded[i].prepareRadixSort();
}
diff --git a/searchlib/src/vespa/searchlib/attribute/loadedstringvalue.h b/searchlib/src/vespa/searchlib/attribute/loadedstringvalue.h
index 87e2574bdb6..15a29096e20 100644
--- a/searchlib/src/vespa/searchlib/attribute/loadedstringvalue.h
+++ b/searchlib/src/vespa/searchlib/attribute/loadedstringvalue.h
@@ -78,7 +78,7 @@ typedef RadixSortable<LoadedValue<const char *> > LoadedStringValue;
typedef SequentialReadModifyWriteInterface<LoadedStringValue> LoadedStringVector;
-typedef SequentialReadModifyWriteVector<LoadedStringValue, vespalib::DefaultAlloc>
+typedef SequentialReadModifyWriteVector<LoadedStringValue>
LoadedStringVectorReal;
diff --git a/searchlib/src/vespa/searchlib/attribute/multinumericenumattribute.h b/searchlib/src/vespa/searchlib/attribute/multinumericenumattribute.h
index 8ef3d28549b..fae23b72dba 100644
--- a/searchlib/src/vespa/searchlib/attribute/multinumericenumattribute.h
+++ b/searchlib/src/vespa/searchlib/attribute/multinumericenumattribute.h
@@ -29,7 +29,7 @@ protected:
typedef typename B::BaseClass::largeint_t largeint_t;
typedef typename B::BaseClass::LoadedNumericValueT LoadedNumericValueT;
typedef typename B::BaseClass::LoadedVector LoadedVector;
- typedef SequentialReadModifyWriteVector<LoadedNumericValueT, vespalib::DefaultAlloc> LoadedVectorR;
+ typedef SequentialReadModifyWriteVector<LoadedNumericValueT> LoadedVectorR;
typedef typename B::BaseClass::Weighted Weighted;
typedef typename B::BaseClass::WeightedInt WeightedInt;
typedef typename B::BaseClass::WeightedFloat WeightedFloat;
diff --git a/searchlib/src/vespa/searchlib/attribute/multivaluemapping.h b/searchlib/src/vespa/searchlib/attribute/multivaluemapping.h
index 3134f826774..c73ec38bcfe 100644
--- a/searchlib/src/vespa/searchlib/attribute/multivaluemapping.h
+++ b/searchlib/src/vespa/searchlib/attribute/multivaluemapping.h
@@ -236,7 +236,7 @@ private:
virtual void clearVector(Index idx) = 0;
public:
- using IndexCopyVector = vespalib::Array<Index, vespalib::DefaultAlloc>;
+ using IndexCopyVector = vespalib::Array<Index>;
void
doneHoldVector(Index idx);
@@ -330,11 +330,11 @@ public:
template <typename VT>
-class MultiValueMappingVector : public vespalib::Array<VT, vespalib::DefaultAlloc>,
+class MultiValueMappingVector : public vespalib::Array<VT>,
public MultiValueMappingVectorBaseBase
{
public:
- typedef vespalib::Array<VT, vespalib::DefaultAlloc> VectorBase;
+ typedef vespalib::Array<VT> VectorBase;
typedef MultiValueMappingFallbackVectorHold<VectorBase> FallBackHold;
MultiValueMappingVector();
MultiValueMappingVector(uint32_t n);
diff --git a/searchlib/src/vespa/searchlib/attribute/postingchange.h b/searchlib/src/vespa/searchlib/attribute/postingchange.h
index b4abe0c7dd2..d728fa89fb0 100644
--- a/searchlib/src/vespa/searchlib/attribute/postingchange.h
+++ b/searchlib/src/vespa/searchlib/attribute/postingchange.h
@@ -18,7 +18,7 @@ template <typename P>
class PostingChange
{
public:
- typedef vespalib::Array<P, vespalib::DefaultAlloc> A;
+ typedef vespalib::Array<P> A;
typedef std::vector<uint32_t> R;
A _additions;
R _removals;
diff --git a/searchlib/src/vespa/searchlib/attribute/postinglistattribute.cpp b/searchlib/src/vespa/searchlib/attribute/postinglistattribute.cpp
index 2d79e80142a..847071cf4f4 100644
--- a/searchlib/src/vespa/searchlib/attribute/postinglistattribute.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/postinglistattribute.cpp
@@ -237,8 +237,7 @@ handleFillPostings(LoadedVector &loaded)
uint32_t docIdLimit = _attr.getNumDocs();
_postingList.resizeBitVectors(docIdLimit, docIdLimit);
if ( ! loaded.empty() ) {
- vespalib::Array<typename LoadedVector::Type,
- vespalib::DefaultAlloc> similarValues;
+ vespalib::Array<typename LoadedVector::Type> similarValues;
typename LoadedVector::Type v = loaded.read();
LoadedValueType prev = v.getValue();
for(size_t i(0), m(loaded.size()); i < m; i++, loaded.next()) {
diff --git a/searchlib/src/vespa/searchlib/attribute/predicate_attribute.cpp b/searchlib/src/vespa/searchlib/attribute/predicate_attribute.cpp
index a0693755666..620188d9630 100644
--- a/searchlib/src/vespa/searchlib/attribute/predicate_attribute.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/predicate_attribute.cpp
@@ -13,7 +13,7 @@ LOG_SETUP(".predicate_attribute");
using document::Predicate;
using document::PredicateFieldValue;
-using vespalib::MMapDataBuffer;
+using vespalib::DataBuffer;
using namespace search::predicate;
namespace search {
@@ -181,7 +181,7 @@ bool PredicateAttribute::onLoad()
FileUtil::LoadedBuffer::UP loaded_buffer = loadDAT();
char *rawBuffer = const_cast<char *>(static_cast<const char *>(loaded_buffer->buffer()));
size_t size = loaded_buffer->size();
- MMapDataBuffer buffer(rawBuffer, size);
+ DataBuffer buffer(rawBuffer, size);
buffer.moveFreeToData(size);
const GenericHeader &header = loaded_buffer->getHeader();
diff --git a/searchlib/src/vespa/searchlib/attribute/singleenumattribute.h b/searchlib/src/vespa/searchlib/attribute/singleenumattribute.h
index ad0cc2a98a3..4768928603b 100644
--- a/searchlib/src/vespa/searchlib/attribute/singleenumattribute.h
+++ b/searchlib/src/vespa/searchlib/attribute/singleenumattribute.h
@@ -24,8 +24,7 @@ protected:
typedef vespalib::GenerationHolder GenerationHolder;
public:
- using EnumIndexCopyVector = vespalib::Array<EnumIndex,
- vespalib::DefaultAlloc>;
+ using EnumIndexCopyVector = vespalib::Array<EnumIndex>;
EnumStoreBase::Index getEnumIndex(DocId docId) const { return _enumIndices[docId]; }
EnumHandle getE(DocId doc) const { return _enumIndices[doc].ref(); }
diff --git a/searchlib/src/vespa/searchlib/attribute/singlenumericenumattribute.h b/searchlib/src/vespa/searchlib/attribute/singlenumericenumattribute.h
index 3793431f75b..125bf5587f3 100644
--- a/searchlib/src/vespa/searchlib/attribute/singlenumericenumattribute.h
+++ b/searchlib/src/vespa/searchlib/attribute/singlenumericenumattribute.h
@@ -30,7 +30,7 @@ protected:
typedef typename B::BaseClass::generation_t generation_t;
typedef typename B::BaseClass::LoadedNumericValueT LoadedNumericValueT;
typedef typename B::BaseClass::LoadedVector LoadedVector;
- typedef SequentialReadModifyWriteVector<LoadedNumericValueT, vespalib::DefaultAlloc> LoadedVectorR;
+ typedef SequentialReadModifyWriteVector<LoadedNumericValueT> LoadedVectorR;
typedef typename SingleValueEnumAttribute<B>::EnumStore EnumStore;
typedef typename SingleValueEnumAttributeBase::EnumIndex EnumIndex;
diff --git a/searchlib/src/vespa/searchlib/attribute/stringbase.h b/searchlib/src/vespa/searchlib/attribute/stringbase.h
index a70cc6ecfab..fde8e3847fc 100644
--- a/searchlib/src/vespa/searchlib/attribute/stringbase.h
+++ b/searchlib/src/vespa/searchlib/attribute/stringbase.h
@@ -19,7 +19,7 @@ class StringEntryType;
class StringAttribute : public AttributeVector
{
public:
- typedef vespalib::Array<uint32_t, vespalib::DefaultAlloc> OffsetVector;
+ typedef vespalib::Array<uint32_t> OffsetVector;
typedef const char * LoadedValueType;
typedef EnumStoreBase::Index EnumIndex;
typedef EnumStoreBase::IndexVector EnumIndexVector;
diff --git a/searchlib/src/vespa/searchlib/attribute/tensorattribute.h b/searchlib/src/vespa/searchlib/attribute/tensorattribute.h
index 3c22d99882d..ec7f41bca18 100644
--- a/searchlib/src/vespa/searchlib/attribute/tensorattribute.h
+++ b/searchlib/src/vespa/searchlib/attribute/tensorattribute.h
@@ -29,7 +29,7 @@ private:
void compactWorst();
public:
- using RefCopyVector = vespalib::Array<RefType, vespalib::DefaultAlloc>;
+ using RefCopyVector = vespalib::Array<RefType>;
using Tensor = vespalib::tensor::Tensor;
TensorAttribute(const vespalib::stringref &baseFileName, const Config &cfg);
~TensorAttribute();
diff --git a/searchlib/src/vespa/searchlib/btree/btreenodeallocator.h b/searchlib/src/vespa/searchlib/btree/btreenodeallocator.h
index 53e949bacbe..3029c287027 100644
--- a/searchlib/src/vespa/searchlib/btree/btreenodeallocator.h
+++ b/searchlib/src/vespa/searchlib/btree/btreenodeallocator.h
@@ -46,8 +46,8 @@ private:
NodeStore _nodeStore;
- typedef vespalib::Array<BTreeNode::Ref, vespalib::DefaultAlloc> RefVector;
- typedef vespalib::Array<BTreeRootBaseType *, vespalib::DefaultAlloc> BTreeRootBaseTypeVector;
+ typedef vespalib::Array<BTreeNode::Ref> RefVector;
+ typedef vespalib::Array<BTreeRootBaseType *> BTreeRootBaseTypeVector;
// Nodes that might not be frozen.
RefVector _internalToFreeze;
diff --git a/searchlib/src/vespa/searchlib/btree/bufferstate.cpp b/searchlib/src/vespa/searchlib/btree/bufferstate.cpp
index 21f548187ee..d0dd62fec4b 100644
--- a/searchlib/src/vespa/searchlib/btree/bufferstate.cpp
+++ b/searchlib/src/vespa/searchlib/btree/bufferstate.cpp
@@ -125,9 +125,8 @@ BufferState::BufferState(void)
_typeId(0),
_clusterSize(0),
_compacting(false),
- _buffer()
+ _buffer(DefaultAlloc::create())
{
- _buffer.reset(new Alloc());
}
@@ -163,14 +162,13 @@ BufferState::onActive(uint32_t bufferId, uint32_t typeId,
assert(_freeListList == NULL || _freeListList->_head != this);
size_t initialSizeNeeded = 0;
- if (bufferId == 0)
+ if (bufferId == 0) {
initialSizeNeeded = typeHandler->getClusterSize();
- size_t allocClusters =
- typeHandler->calcClustersToAlloc(initialSizeNeeded + sizeNeeded,
- maxClusters);
+ }
+ size_t allocClusters = typeHandler->calcClustersToAlloc(initialSizeNeeded + sizeNeeded, maxClusters);
size_t allocSize = allocClusters * typeHandler->getClusterSize();
assert(allocSize >= initialSizeNeeded + sizeNeeded);
- _buffer.reset(new Alloc(allocSize * typeHandler->elementSize()));
+ _buffer.create(allocSize * typeHandler->elementSize()).swap(_buffer);
buffer = _buffer->get();
typeHandler->onActive(&_usedElems);
assert(buffer != NULL);
@@ -218,7 +216,7 @@ BufferState::onFree(void *&buffer)
assert(_deadElems <= _usedElems);
assert(_holdElems == _usedElems - _deadElems);
_typeHandler->destroyElements(buffer, _usedElems);
- Alloc().swap(*_buffer);
+ _buffer.create().swap(_buffer);
_typeHandler->onFree(_usedElems);
buffer = NULL;
_usedElems = 0;
@@ -334,10 +332,9 @@ BufferState::fallbackResize(uint64_t newSize,
size_t allocSize = allocClusters * _typeHandler->getClusterSize();
assert(allocSize >= newSize);
assert(allocSize > _allocElems);
- Alloc::UP newBuffer(std::make_unique<Alloc>
- (allocSize * _typeHandler->elementSize()));
- _typeHandler->fallbackCopy(newBuffer->get(), buffer, _usedElems);
- holdBuffer.swap(*_buffer);
+ Alloc newBuffer = _buffer.create(allocSize * _typeHandler->elementSize());
+ _typeHandler->fallbackCopy(newBuffer.get(), buffer, _usedElems);
+ holdBuffer.swap(_buffer);
std::atomic_thread_fence(std::memory_order_release);
_buffer = std::move(newBuffer);
buffer = _buffer->get();
diff --git a/searchlib/src/vespa/searchlib/btree/bufferstate.h b/searchlib/src/vespa/searchlib/btree/bufferstate.h
index 3c7a3557952..bbb8f77d5ef 100644
--- a/searchlib/src/vespa/searchlib/btree/bufferstate.h
+++ b/searchlib/src/vespa/searchlib/btree/bufferstate.h
@@ -13,14 +13,8 @@
namespace search {
namespace btree {
-
class BufferTypeBase
{
-private:
- BufferTypeBase(const BufferTypeBase &rhs);
-
- BufferTypeBase &
- operator=(const BufferTypeBase &rhs);
protected:
uint32_t _clusterSize; // Number of elements in an allocation unit
uint32_t _minClusters; // Minimum number of clusters to allocate
@@ -32,47 +26,21 @@ protected:
const size_t *_lastUsedElems; // used elements in last active buffer
public:
- BufferTypeBase(uint32_t clusterSize,
- uint32_t minClusters,
- uint32_t maxClusters);
-
- virtual
- ~BufferTypeBase(void);
-
- virtual void
- destroyElements(void *buffer, size_t numElements) = 0;
-
- virtual void
- fallbackCopy(void *newBuffer,
- const void *oldBuffer,
- size_t numElements) = 0;
-
- virtual void
- cleanInitialElements(void *buffer) = 0;
-
- virtual size_t
- elementSize(void) const = 0;
-
- virtual void
- cleanHold(void *buffer, uint64_t offset, uint64_t len) = 0;
-
- uint32_t
- getClusterSize(void) const
- {
- return _clusterSize;
- }
-
- void
- flushLastUsed(void);
-
- void
- onActive(const size_t *usedElems);
-
- void
- onHold(const size_t *usedElems);
-
- virtual void
- onFree(size_t usedElems);
+
+ BufferTypeBase(const BufferTypeBase &rhs) = delete;
+ BufferTypeBase & operator=(const BufferTypeBase &rhs) = delete;
+ BufferTypeBase(uint32_t clusterSize, uint32_t minClusters, uint32_t maxClusters);
+ virtual ~BufferTypeBase();
+ virtual void destroyElements(void *buffer, size_t numElements) = 0;
+ virtual void fallbackCopy(void *newBuffer, const void *oldBuffer, size_t numElements) = 0;
+ virtual void cleanInitialElements(void *buffer) = 0;
+ virtual size_t elementSize() const = 0;
+ virtual void cleanHold(void *buffer, uint64_t offset, uint64_t len) = 0;
+ uint32_t getClusterSize() const { return _clusterSize; }
+ void flushLastUsed();
+ void onActive(const size_t *usedElems);
+ void onHold(const size_t *usedElems);
+ virtual void onFree(size_t usedElems);
/**
* Calculate number of clusters to allocate for new buffer.
@@ -82,9 +50,7 @@ public:
*
* @return number of clusters to allocate for new buffer
*/
- virtual size_t
- calcClustersToAlloc(size_t sizeNeeded,
- uint64_t clusterRefSize) const;
+ virtual size_t calcClustersToAlloc(size_t sizeNeeded, uint64_t clusterRefSize) const;
uint32_t getActiveBuffers() const { return _activeBuffers; }
};
@@ -93,41 +59,21 @@ public:
template <typename EntryType>
class BufferType : public BufferTypeBase
{
-private:
- BufferType(const BufferType &rhs);
-
- BufferType &
- operator=(const BufferType &rhs);
public:
EntryType _emptyEntry;
- BufferType(uint32_t clusterSize,
- uint32_t minClusters,
- uint32_t maxClusters)
+ BufferType(const BufferType &rhs) = delete;
+ BufferType & operator=(const BufferType &rhs) = delete;
+ BufferType(uint32_t clusterSize, uint32_t minClusters, uint32_t maxClusters)
: BufferTypeBase(clusterSize, minClusters, maxClusters),
_emptyEntry()
- {
- }
-
- virtual void
- destroyElements(void *buffer, size_t numElements);
+ { }
- virtual void
- fallbackCopy(void *newBuffer,
- const void *oldBuffer,
- size_t numElements);
-
- virtual void
- cleanInitialElements(void *buffer);
-
- virtual void
- cleanHold(void *buffer, uint64_t offset, uint64_t len);
-
- virtual size_t
- elementSize(void) const
- {
- return sizeof(EntryType);
- }
+ void destroyElements(void *buffer, size_t numElements) override;
+ void fallbackCopy(void *newBuffer, const void *oldBuffer, size_t numElements) override;
+ void cleanInitialElements(void *buffer) override;
+ void cleanHold(void *buffer, uint64_t offset, uint64_t len) override;
+ size_t elementSize() const override { return sizeof(EntryType); }
};
@@ -186,25 +132,20 @@ BufferType<EntryType>::cleanHold(void *buffer, uint64_t offset, uint64_t len)
class BufferState
{
public:
- typedef vespalib::DefaultAlloc Alloc;
+ typedef vespalib::alloc::Alloc Alloc;
class FreeListList
{
public:
BufferState *_head;
- FreeListList(void)
- : _head(NULL)
- {
- }
-
- ~FreeListList(void);
+ FreeListList() : _head(NULL) { }
+ ~FreeListList();
};
- typedef vespalib::Array<EntryRef, vespalib::DefaultAlloc> FreeList;
+ typedef vespalib::Array<EntryRef> FreeList;
- enum State
- {
+ enum State {
FREE,
ACTIVE,
HOLD
@@ -224,18 +165,17 @@ public:
BufferState *_prevHasFree;
BufferTypeBase *_typeHandler;
- uint32_t _typeId;
- uint32_t _clusterSize;
- bool _compacting;
+ uint32_t _typeId;
+ uint32_t _clusterSize;
+ bool _compacting;
/*
* TODO: Check if per-buffer free lists are useful, or if
*compaction should always be used to free up whole buffers.
*/
- BufferState(void);
-
- ~BufferState(void);
+ BufferState();
+ ~BufferState();
/**
* Transition from FREE to ACTIVE state.
@@ -250,21 +190,17 @@ public:
*/
void
onActive(uint32_t bufferId, uint32_t typeId, BufferTypeBase *typeHandler,
- size_t sizeNeeded,
- size_t maxSize,
- void *&buffer);
+ size_t sizeNeeded, size_t maxSize, void *&buffer);
/**
* Transition from ACTIVE to HOLD state.
*/
- void
- onHold(void);
+ void onHold();
/**
* Transition from HOLD to FREE state.
*/
- void
- onFree(void *&buffer);
+ void onFree(void *&buffer);
/**
* Set list of buffer states with nonempty free lists.
@@ -272,115 +208,57 @@ public:
* @param freeListList List of buffer states. If NULL then free lists
* are disabled.
*/
- void
- setFreeListList(FreeListList *freeListList);
+ void setFreeListList(FreeListList *freeListList);
/**
* Add buffer state to list of buffer states with nonempty free lists.
*/
- void
- addToFreeListList(void);
+ void addToFreeListList();
/**
* Remove buffer state from list of buffer states with nonempty free lists.
*/
- void
- removeFromFreeListList(void);
+ void removeFromFreeListList();
/**
* Disable hold of elements, just mark then as dead without
* cleanup. Typically used when tearing down data structure in a
* controlled manner.
*/
- void
- disableElemHoldList(void);
+ void disableElemHoldList();
/**
* Pop element from free list.
*/
- EntryRef
- popFreeList(void)
- {
+ EntryRef popFreeList() {
EntryRef ret = _freeList.back();
_freeList.pop_back();
- if (_freeList.empty())
+ if (_freeList.empty()) {
removeFromFreeListList();
+ }
_deadElems -= _clusterSize;
return ret;
}
-
- size_t
- size(void) const
- {
- return _usedElems;
- }
-
- size_t
- capacity(void) const
- {
- return _allocElems;
- }
-
- size_t
- remaining(void) const
- {
- return _allocElems - _usedElems;
- }
-
- void
- pushed_back(uint64_t len)
- {
- _usedElems += len;
- }
-
- void
- cleanHold(void *buffer, uint64_t offset, uint64_t len)
- {
- _typeHandler->cleanHold(buffer, offset, len);
- }
-
- void
- dropBuffer(void *&buffer);
-
- uint32_t
- getTypeId(void) const
- {
- return _typeId;
- }
-
- uint32_t
- getClusterSize(void) const
- {
- return _clusterSize;
- }
-
+ size_t size() const { return _usedElems; }
+ size_t capacity() const { return _allocElems; }
+ size_t remaining() const { return _allocElems - _usedElems; }
+ void pushed_back(uint64_t len) { _usedElems += len; }
+ void cleanHold(void *buffer, uint64_t offset, uint64_t len) { _typeHandler->cleanHold(buffer, offset, len); }
+ void dropBuffer(void *&buffer);
+ uint32_t getTypeId() const { return _typeId; }
+ uint32_t getClusterSize() const { return _clusterSize; }
uint64_t getDeadElems() const { return _deadElems; }
-
- bool
- getCompacting(void) const
- {
- return _compacting;
- }
-
- void
- setCompacting(void)
- {
- _compacting = true;
- }
-
- void
- fallbackResize(uint64_t newSize,
- size_t maxClusters,
- void *&buffer,
- Alloc &holdBuffer);
+ bool getCompacting() const { return _compacting; }
+ void setCompacting() { _compacting = true; }
+ void fallbackResize(uint64_t newSize, size_t maxClusters, void *&buffer, Alloc &holdBuffer);
bool isActive(uint32_t typeId) const {
return ((_state == ACTIVE) && (_typeId == typeId));
}
private:
- Alloc::UP _buffer;
+ Alloc _buffer;
};
diff --git a/searchlib/src/vespa/searchlib/btree/datastorebase.h b/searchlib/src/vespa/searchlib/btree/datastorebase.h
index 0c44b485d18..f948ada3d2f 100644
--- a/searchlib/src/vespa/searchlib/btree/datastorebase.h
+++ b/searchlib/src/vespa/searchlib/btree/datastorebase.h
@@ -57,7 +57,7 @@ protected:
}
};
- typedef vespalib::Array<ElemHold1ListElem, vespalib::DefaultAlloc> ElemHold1List;
+ typedef vespalib::Array<ElemHold1ListElem> ElemHold1List;
typedef std::deque<ElemHold2ListElem> ElemHold2List;
class FallbackHold : public vespalib::GenerationHeldBase
diff --git a/searchlib/src/vespa/searchlib/common/allocatedbitvector.cpp b/searchlib/src/vespa/searchlib/common/allocatedbitvector.cpp
index 59d190b2b50..d6795f4b583 100644
--- a/searchlib/src/vespa/searchlib/common/allocatedbitvector.cpp
+++ b/searchlib/src/vespa/searchlib/common/allocatedbitvector.cpp
@@ -18,7 +18,7 @@ void AllocatedBitVector::alloc()
uint32_t words = capacityWords();
words += (-words & 15); // Pad to 64 byte alignment
const size_t sz(words * sizeof(Word));
- Alloc(sz).swap(_alloc);
+ DefaultAlloc(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/allocatedbitvector.h b/searchlib/src/vespa/searchlib/common/allocatedbitvector.h
index 8a52a07e29b..df1de516156 100644
--- a/searchlib/src/vespa/searchlib/common/allocatedbitvector.h
+++ b/searchlib/src/vespa/searchlib/common/allocatedbitvector.h
@@ -17,8 +17,7 @@ class BitVectorTest;
class AllocatedBitVector : public BitVector
{
public:
- typedef vespalib::AutoAlloc<0x800000, 0x1000> Alloc;
-
+ using Alloc = vespalib::alloc::Alloc;
/**
* Class constructor specifying size but not content. New bitvector
* is cleared.
diff --git a/searchlib/src/vespa/searchlib/common/rcuvector.h b/searchlib/src/vespa/searchlib/common/rcuvector.h
index 9c5954848c4..3c9274e3e94 100644
--- a/searchlib/src/vespa/searchlib/common/rcuvector.h
+++ b/searchlib/src/vespa/searchlib/common/rcuvector.h
@@ -44,7 +44,7 @@ class RcuVectorBase
"Value type must be trivially destructible");
protected:
- typedef vespalib::Array<T, vespalib::DefaultAlloc> Array;
+ typedef vespalib::Array<T> Array;
typedef vespalib::GenerationHandler::generation_t generation_t;
typedef vespalib::GenerationHolder GenerationHolder;
Array _data;
diff --git a/searchlib/src/vespa/searchlib/diskindex/docidmapper.h b/searchlib/src/vespa/searchlib/diskindex/docidmapper.h
index 43e1ea44b89..f150e8636a5 100644
--- a/searchlib/src/vespa/searchlib/diskindex/docidmapper.h
+++ b/searchlib/src/vespa/searchlib/diskindex/docidmapper.h
@@ -12,7 +12,7 @@ class BitVector;
namespace diskindex
{
-typedef vespalib::Array<uint8_t, vespalib::DefaultAlloc> SelectorArray;
+typedef vespalib::Array<uint8_t> SelectorArray;
class DocIdMapping
{
diff --git a/searchlib/src/vespa/searchlib/diskindex/indexbuilder.cpp b/searchlib/src/vespa/searchlib/diskindex/indexbuilder.cpp
index a88ce029814..0ec75cfbdf2 100644
--- a/searchlib/src/vespa/searchlib/diskindex/indexbuilder.cpp
+++ b/searchlib/src/vespa/searchlib/diskindex/indexbuilder.cpp
@@ -152,9 +152,9 @@ public:
}
};
- typedef vespalib::Array<FHWordDocFieldFeatures, vespalib::DefaultAlloc> FHWordDocFieldFeaturesVector;
- typedef vespalib::Array<FHWordDocElementFeatures, vespalib::DefaultAlloc> FHWordDocElementFeaturesVector;
- typedef vespalib::Array<FHWordDocElementWordPosFeatures, vespalib::DefaultAlloc> FHWordDocElementWordPosFeaturesVector;
+ typedef vespalib::Array<FHWordDocFieldFeatures> FHWordDocFieldFeaturesVector;
+ typedef vespalib::Array<FHWordDocElementFeatures> FHWordDocElementFeaturesVector;
+ typedef vespalib::Array<FHWordDocElementWordPosFeatures> FHWordDocElementWordPosFeaturesVector;
FHWordDocFieldFeaturesVector _wdff;
FHWordDocElementFeaturesVector _wdfef;
diff --git a/searchlib/src/vespa/searchlib/diskindex/wordnummapper.h b/searchlib/src/vespa/searchlib/diskindex/wordnummapper.h
index a1a72757f22..d12e0211b94 100644
--- a/searchlib/src/vespa/searchlib/diskindex/wordnummapper.h
+++ b/searchlib/src/vespa/searchlib/diskindex/wordnummapper.h
@@ -14,7 +14,7 @@ class WordNumMapper;
class WordNumMapping
{
- typedef vespalib::Array<uint64_t, vespalib::DefaultAlloc> Array;
+ typedef vespalib::Array<uint64_t> Array;
static uint64_t
noWordNumHigh(void)
diff --git a/searchlib/src/vespa/searchlib/docstore/documentstore.h b/searchlib/src/vespa/searchlib/docstore/documentstore.h
index d44c94fe7f8..7ca3b98d525 100644
--- a/searchlib/src/vespa/searchlib/docstore/documentstore.h
+++ b/searchlib/src/vespa/searchlib/docstore/documentstore.h
@@ -173,7 +173,7 @@ private:
_compressedSize(rhs._compressedSize),
_uncompressedSize(rhs._uncompressedSize),
_compression(rhs._compression),
- _buf(rhs.size())
+ _buf(vespalib::DefaultAlloc::create(rhs.size()))
{
memcpy(get(), rhs.get(), size());
}
@@ -213,7 +213,7 @@ private:
size_t _compressedSize;
size_t _uncompressedSize;
document::CompressionConfig::Type _compression;
- vespalib::DefaultAlloc _buf;
+ vespalib::alloc::Alloc _buf;
};
class BackingStore {
public:
diff --git a/searchlib/src/vespa/searchlib/docstore/filechunk.cpp b/searchlib/src/vespa/searchlib/docstore/filechunk.cpp
index 36ee94f9f8f..f76d12ed7aa 100644
--- a/searchlib/src/vespa/searchlib/docstore/filechunk.cpp
+++ b/searchlib/src/vespa/searchlib/docstore/filechunk.cpp
@@ -293,7 +293,7 @@ public:
}
};
-typedef vespalib::Array<TmpChunkMeta, vespalib::DefaultAlloc> TmpChunkMetaV;
+typedef vespalib::Array<TmpChunkMeta> TmpChunkMetaV;
namespace {
diff --git a/searchlib/src/vespa/searchlib/docstore/filechunk.h b/searchlib/src/vespa/searchlib/docstore/filechunk.h
index 5c2006a7083..27cccc59290 100644
--- a/searchlib/src/vespa/searchlib/docstore/filechunk.h
+++ b/searchlib/src/vespa/searchlib/docstore/filechunk.h
@@ -345,7 +345,7 @@ protected:
ssize_t read(uint32_t lid, SubChunkId chunkId, const ChunkInfo & chunkInfo, vespalib::DataBuffer & buffer) const;
void read(LidInfoWithLidV::const_iterator begin, size_t count, ChunkInfo ci, IBufferVisitor & visitor) const;
- typedef vespalib::Array<ChunkInfo, vespalib::DefaultAlloc> ChunkInfoVector;
+ typedef vespalib::Array<ChunkInfo> ChunkInfoVector;
const IBucketizer * _bucketizer;
size_t _addedBytes;
TuneFileSummary _tune;
diff --git a/searchlib/src/vespa/searchlib/docstore/storebybucket.h b/searchlib/src/vespa/searchlib/docstore/storebybucket.h
index a7144596d0b..b6a25ef1dff 100644
--- a/searchlib/src/vespa/searchlib/docstore/storebybucket.h
+++ b/searchlib/src/vespa/searchlib/docstore/storebybucket.h
@@ -60,7 +60,7 @@ private:
uint32_t _chunkId;
uint32_t _lid;
};
- using IndexVector = vespalib::Array<Index, vespalib::DefaultAlloc>;
+ using IndexVector = vespalib::Array<Index>;
uint64_t _chunkSerial;
Chunk::UP _current;
std::map<uint64_t, IndexVector> _where;
diff --git a/searchlib/src/vespa/searchlib/docstore/visitcache.cpp b/searchlib/src/vespa/searchlib/docstore/visitcache.cpp
index 43a8c1b33aa..79d7fd4e26d 100644
--- a/searchlib/src/vespa/searchlib/docstore/visitcache.cpp
+++ b/searchlib/src/vespa/searchlib/docstore/visitcache.cpp
@@ -35,7 +35,7 @@ size_t getBufferSize(const BlobSet::Positions & p) {
}
-BlobSet::BlobSet(const Positions & positions, vespalib::DefaultAlloc && buffer) :
+BlobSet::BlobSet(const Positions & positions, vespalib::alloc::Alloc && buffer) :
_positions(positions),
_buffer(std::move(buffer), getBufferSize(_positions))
{
diff --git a/searchlib/src/vespa/searchlib/docstore/visitcache.h b/searchlib/src/vespa/searchlib/docstore/visitcache.h
index fb1b61310f8..518280bcc09 100644
--- a/searchlib/src/vespa/searchlib/docstore/visitcache.h
+++ b/searchlib/src/vespa/searchlib/docstore/visitcache.h
@@ -47,7 +47,7 @@ public:
using Positions = std::vector<LidPosition>;
BlobSet();
- BlobSet(const Positions & positions, vespalib::DefaultAlloc && buffer);
+ BlobSet(const Positions & positions, vespalib::alloc::Alloc && buffer);
void append(uint32_t lid, vespalib::ConstBufferRef blob);
void remove(uint32_t lid);
const Positions & getPositions() const { return _positions; }
diff --git a/searchlib/src/vespa/searchlib/engine/searchreply.h b/searchlib/src/vespa/searchlib/engine/searchreply.h
index 692806114ee..0e7ab43e66d 100644
--- a/searchlib/src/vespa/searchlib/engine/searchreply.h
+++ b/searchlib/src/vespa/searchlib/engine/searchreply.h
@@ -56,7 +56,7 @@ public:
search::HitRank maxRank;
std::vector<uint32_t> sortIndex;
std::vector<char> sortData;
- vespalib::Array<char, vespalib::DefaultAlloc> groupResult;
+ vespalib::Array<char> groupResult;
bool useCoverage;
Coverage coverage;
bool useWideHits;
diff --git a/searchlib/src/vespa/searchlib/grouping/sketch.h b/searchlib/src/vespa/searchlib/grouping/sketch.h
index 0a475a9e805..e336955f337 100644
--- a/searchlib/src/vespa/searchlib/grouping/sketch.h
+++ b/searchlib/src/vespa/searchlib/grouping/sketch.h
@@ -226,19 +226,16 @@ decompress_buckets_from(char *buffer, uint32_t size) {
memcpy(bucket, buffer, BUCKET_COUNT);
} else {
vespalib::ConstBufferRef compressed(buffer, size);
- vespalib::DataBuffer uncompressed(reinterpret_cast<char *>(&bucket[0]),
- BUCKET_COUNT);
- document::decompress(document::CompressionConfig::LZ4, BUCKET_COUNT,
- compressed, uncompressed, false);
+ vespalib::DataBuffer uncompressed(reinterpret_cast<char *>(&bucket[0]), BUCKET_COUNT);
+ document::decompress(document::CompressionConfig::LZ4, BUCKET_COUNT, compressed, uncompressed, false);
}
}
template <int BucketBits, typename HashT>
void NormalSketch<BucketBits, HashT>::
serialize(vespalib::Serializer &os) const {
- vespalib::DefaultAlloc backing(LZ4_compressBound(BUCKET_COUNT));
+ vespalib::alloc::Alloc backing(vespalib::DefaultAlloc::create(LZ4_compressBound(BUCKET_COUNT)));
char * compress_array(static_cast<char *>(backing.get()));
- uint32_t size =
- compress_buckets_into(compress_array, backing.size());
+ uint32_t size = compress_buckets_into(compress_array, backing.size());
os << BUCKET_COUNT << size;
for (size_t i = 0; i < size; ++i) {
os << static_cast<uint8_t>(compress_array[i]);
diff --git a/searchlib/src/vespa/searchlib/memoryindex/fieldinverter.h b/searchlib/src/vespa/searchlib/memoryindex/fieldinverter.h
index 1f72c8e62b4..47d1031d546 100644
--- a/searchlib/src/vespa/searchlib/memoryindex/fieldinverter.h
+++ b/searchlib/src/vespa/searchlib/memoryindex/fieldinverter.h
@@ -98,7 +98,7 @@ private:
FieldInverter &operator=(const FieldInverter &) = delete;
FieldInverter &operator=(const FieldInverter &&) = delete;
- typedef vespalib::Array<char, vespalib::DefaultAlloc> WordBuffer;
+ typedef vespalib::Array<char> WordBuffer;
class ElemInfo
{
diff --git a/searchlib/src/vespa/searchlib/memoryindex/memoryfieldindex.cpp b/searchlib/src/vespa/searchlib/memoryindex/memoryfieldindex.cpp
index 88b718e1860..ba0c8e95efa 100644
--- a/searchlib/src/vespa/searchlib/memoryindex/memoryfieldindex.cpp
+++ b/searchlib/src/vespa/searchlib/memoryindex/memoryfieldindex.cpp
@@ -173,7 +173,7 @@ MemoryFieldIndex::dump(search::index::IndexBuilder & indexBuilder)
vespalib::stringref word;
FeatureStore::DecodeContextCooked decoder(NULL);
DocIdAndFeatures features;
- vespalib::Array<uint32_t, vespalib::DefaultAlloc> wordMap(_numUniqueWords + 1, 0);
+ vespalib::Array<uint32_t> wordMap(_numUniqueWords + 1, 0);
_featureStore.setupForField(_fieldId, decoder);
for (DictionaryTree::Iterator itr = _dict.begin(); itr.valid(); ++itr) {
const WordKey & wk = itr.getKey();
diff --git a/searchlib/src/vespa/searchlib/predicate/document_features_store.h b/searchlib/src/vespa/searchlib/predicate/document_features_store.h
index 314e7347f27..8d910f8506c 100644
--- a/searchlib/src/vespa/searchlib/predicate/document_features_store.h
+++ b/searchlib/src/vespa/searchlib/predicate/document_features_store.h
@@ -72,7 +72,7 @@ public:
typedef std::unordered_set<uint64_t> FeatureSet;
DocumentFeaturesStore(uint32_t arity);
- DocumentFeaturesStore(vespalib::MMapDataBuffer &buffer);
+ DocumentFeaturesStore(vespalib::DataBuffer &buffer);
~DocumentFeaturesStore();
void insert(uint64_t featureId, uint32_t docId);
@@ -81,7 +81,7 @@ public:
void remove(uint32_t docId);
search::MemoryUsage getMemoryUsage() const;
- void serialize(vespalib::MMapDataBuffer &buffer) const;
+ void serialize(vespalib::DataBuffer &buffer) const;
};
} // namespace predicate
diff --git a/searchlib/src/vespa/searchlib/predicate/predicate_index.cpp b/searchlib/src/vespa/searchlib/predicate/predicate_index.cpp
index 81533c36951..6e597d55f3b 100644
--- a/searchlib/src/vespa/searchlib/predicate/predicate_index.cpp
+++ b/searchlib/src/vespa/searchlib/predicate/predicate_index.cpp
@@ -12,7 +12,7 @@
LOG_SETUP(".predicate_index");
using search::btree::EntryRef;
-using vespalib::MMapDataBuffer;
+using vespalib::DataBuffer;
using std::vector;
namespace search {
@@ -63,7 +63,7 @@ class IntervalSerializer : public PostingSerializer<EntryRef> {
public:
IntervalSerializer(const PredicateIntervalStore &store) : _store(store) {}
virtual void serialize(const EntryRef &ref,
- vespalib::MMapDataBuffer &buffer) const {
+ vespalib::DataBuffer &buffer) const {
uint32_t size;
IntervalT single_buf;
const IntervalT *interval = _store.get(ref, size, &single_buf);
@@ -81,7 +81,7 @@ class IntervalDeserializer : public PostingDeserializer<EntryRef> {
PredicateIntervalStore &_store;
public:
IntervalDeserializer(PredicateIntervalStore &store) : _store(store) {}
- virtual EntryRef deserialize(vespalib::MMapDataBuffer &buffer) {
+ virtual EntryRef deserialize(vespalib::DataBuffer &buffer) {
std::vector<IntervalT> intervals;
size_t size = buffer.readInt16();
for (uint32_t i = 0; i < size; ++i) {
@@ -95,7 +95,7 @@ public:
PredicateIndex::PredicateIndex(GenerationHandler &generation_handler, GenerationHolder &genHolder,
const DocIdLimitProvider &limit_provider,
- const SimpleIndexConfig &simple_index_config, MMapDataBuffer &buffer,
+ const SimpleIndexConfig &simple_index_config, DataBuffer &buffer,
SimpleIndexDeserializeObserver<> & observer, uint32_t version)
: _arity(0),
_generation_handler(generation_handler),
@@ -125,7 +125,7 @@ PredicateIndex::PredicateIndex(GenerationHandler &generation_handler, Generation
commit();
}
-void PredicateIndex::serialize(MMapDataBuffer &buffer) const {
+void PredicateIndex::serialize(DataBuffer &buffer) const {
_features_store.serialize(buffer);
buffer.writeInt16(_arity);
buffer.writeInt32(_zero_constraint_docs.size());
diff --git a/searchlib/src/vespa/searchlib/predicate/predicate_index.h b/searchlib/src/vespa/searchlib/predicate/predicate_index.h
index d2e5c1f268e..3673f4378ad 100644
--- a/searchlib/src/vespa/searchlib/predicate/predicate_index.h
+++ b/searchlib/src/vespa/searchlib/predicate/predicate_index.h
@@ -82,10 +82,10 @@ public:
// The observer can be used to gain some insight into what has been added to the index..
PredicateIndex(GenerationHandler &generation_handler, GenerationHolder &genHolder,
const DocIdLimitProvider &limit_provider,
- const SimpleIndexConfig &simple_index_config, vespalib::MMapDataBuffer &buffer,
+ const SimpleIndexConfig &simple_index_config, vespalib::DataBuffer &buffer,
SimpleIndexDeserializeObserver<> & observer, uint32_t version);
- void serialize(vespalib::MMapDataBuffer &buffer) const;
+ void serialize(vespalib::DataBuffer &buffer) const;
void onDeserializationCompleted();
void indexEmptyDocument(uint32_t doc_id);
diff --git a/searchlib/src/vespa/searchlib/predicate/predicate_interval.h b/searchlib/src/vespa/searchlib/predicate/predicate_interval.h
index fede659582a..3a288c4aedb 100644
--- a/searchlib/src/vespa/searchlib/predicate/predicate_interval.h
+++ b/searchlib/src/vespa/searchlib/predicate/predicate_interval.h
@@ -16,10 +16,10 @@ struct Interval {
Interval() : interval(0) {}
Interval(uint32_t interval_) : interval(interval_) {}
- void serialize(vespalib::MMapDataBuffer &buffer) const {
+ void serialize(vespalib::DataBuffer &buffer) const {
buffer.writeInt32(interval);
}
- static Interval deserialize(vespalib::MMapDataBuffer &buffer) {
+ static Interval deserialize(vespalib::DataBuffer &buffer) {
return Interval{buffer.readInt32()};
}
bool operator==(const Interval &other) const {
@@ -42,11 +42,11 @@ struct IntervalWithBounds {
IntervalWithBounds() : interval(0), bounds(0) {}
IntervalWithBounds(uint32_t interval_, uint32_t bounds_) : interval(interval_), bounds(bounds_) {}
- void serialize(vespalib::MMapDataBuffer &buffer) const {
+ void serialize(vespalib::DataBuffer &buffer) const {
buffer.writeInt32(interval);
buffer.writeInt32(bounds);
}
- static IntervalWithBounds deserialize(vespalib::MMapDataBuffer &buffer) {
+ static IntervalWithBounds deserialize(vespalib::DataBuffer &buffer) {
uint32_t interval = buffer.readInt32();
uint32_t bounds = buffer.readInt32();
return IntervalWithBounds{interval, bounds};
diff --git a/searchlib/src/vespa/searchlib/predicate/simple_index.h b/searchlib/src/vespa/searchlib/predicate/simple_index.h
index be6fc098682..b61f31f79a0 100644
--- a/searchlib/src/vespa/searchlib/predicate/simple_index.h
+++ b/searchlib/src/vespa/searchlib/predicate/simple_index.h
@@ -31,13 +31,13 @@ template <typename Posting>
struct PostingSerializer {
virtual ~PostingSerializer() {}
virtual void serialize(const Posting &posting,
- vespalib::MMapDataBuffer &buffer) const = 0;
+ vespalib::DataBuffer &buffer) const = 0;
};
template <typename Posting>
struct PostingDeserializer {
virtual ~PostingDeserializer() {}
- virtual Posting deserialize(vespalib::MMapDataBuffer &buffer) = 0;
+ virtual Posting deserialize(vespalib::DataBuffer &buffer) = 0;
};
struct DocIdLimitProvider {
@@ -195,9 +195,9 @@ public:
: _generation_holder(generation_holder), _config(config), _limit_provider(provider) {}
~SimpleIndex();
- void serialize(vespalib::MMapDataBuffer &buffer,
+ void serialize(vespalib::DataBuffer &buffer,
const PostingSerializer<Posting> &serializer) const;
- void deserialize(vespalib::MMapDataBuffer &buffer,
+ void deserialize(vespalib::DataBuffer &buffer,
PostingDeserializer<Posting> &deserializer,
SimpleIndexDeserializeObserver<Key, DocId> &observer, uint32_t version);
diff --git a/searchlib/src/vespa/searchlib/queryeval/predicate_blueprint.cpp b/searchlib/src/vespa/searchlib/queryeval/predicate_blueprint.cpp
index 70903788992..1610267c255 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::DefaultAlloc kv(mfh.second);
+ vespalib::alloc::Alloc kv(vespalib::DefaultAlloc::create(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 aeab9d4175f..616460f9e55 100644
--- a/searchlib/src/vespa/searchlib/queryeval/predicate_blueprint.h
+++ b/searchlib/src/vespa/searchlib/queryeval/predicate_blueprint.h
@@ -72,7 +72,7 @@ private:
const PredicateAttribute & _attribute;
const predicate::PredicateIndex &_index;
- vespalib::DefaultAlloc _kVBacking;
+ vespalib::alloc::Alloc _kVBacking;
BitVectorCache::CountVector _kV;
BitVectorCache::KeySet _cachedFeatures;
diff --git a/searchlib/src/vespa/searchlib/util/fileutil.h b/searchlib/src/vespa/searchlib/util/fileutil.h
index 69d2cc557a6..b61c4e9d0ac 100644
--- a/searchlib/src/vespa/searchlib/util/fileutil.h
+++ b/searchlib/src/vespa/searchlib/util/fileutil.h
@@ -295,11 +295,11 @@ public:
virtual void rewind() = 0;
};
-template <typename T, typename A=vespalib::HeapAlloc>
-class SequentialReadModifyWriteVector : public SequentialReadModifyWriteInterface<T>, public vespalib::Array<T, A>
+template <typename T>
+class SequentialReadModifyWriteVector : public SequentialReadModifyWriteInterface<T>, public vespalib::Array<T>
{
private:
- typedef vespalib::Array<T, A> Vector;
+ typedef vespalib::Array<T> Vector;
public:
SequentialReadModifyWriteVector() : Vector(), _rp(0), _wp(0) { }
SequentialReadModifyWriteVector(size_t sz) : Vector(sz), _rp(0), _wp(0) { }
diff --git a/staging_vespalib/src/tests/array/allocinarray_benchmark.cpp b/staging_vespalib/src/tests/array/allocinarray_benchmark.cpp
index 9f365ff937c..426cb7ee3b8 100644
--- a/staging_vespalib/src/tests/array/allocinarray_benchmark.cpp
+++ b/staging_vespalib/src/tests/array/allocinarray_benchmark.cpp
@@ -60,7 +60,7 @@ private:
typedef TreeNode<long> N;
typedef RefTreeNode<long> R;
-typedef AllocInArray<R, vespalib::Array<R, MMapAlloc> > Store;
+typedef AllocInArray<R, vespalib::Array<R> > Store;
void populate(Store & store, uint32_t parent, size_t depth)
{
diff --git a/staging_vespalib/src/tests/array/allocinarray_test.cpp b/staging_vespalib/src/tests/array/allocinarray_test.cpp
index 3a40a71f288..de6e5792b35 100644
--- a/staging_vespalib/src/tests/array/allocinarray_test.cpp
+++ b/staging_vespalib/src/tests/array/allocinarray_test.cpp
@@ -26,7 +26,7 @@ Test::Main()
TEST_INIT("allocinarray_test");
testAllocInArray<int64_t, vespalib::Array<int64_t> >();
- testAllocInArray<int64_t, vespalib::Array<int64_t, vespalib::DefaultAlloc> >();
+ testAllocInArray<int64_t, vespalib::Array<int64_t> >();
testAllocInArray<int64_t, std::vector<int64_t> >();
testAllocInArray<int64_t, std::deque<int64_t> >();
diff --git a/staging_vespalib/src/vespa/vespalib/data/databuffer.cpp b/staging_vespalib/src/vespa/vespalib/data/databuffer.cpp
index 26a7eac824f..e046415e8e8 100644
--- a/staging_vespalib/src/vespa/vespalib/data/databuffer.cpp
+++ b/staging_vespalib/src/vespa/vespalib/data/databuffer.cpp
@@ -12,21 +12,20 @@ size_t padbefore(size_t alignment, const char *buf) {
}
}
-template <typename T>
-DataBufferT<T>::DataBufferT(size_t len, size_t alignment)
+DataBuffer::DataBuffer(size_t len, size_t alignment, const Alloc & initial)
: _alignment(alignment),
_externalBuf(NULL),
_bufstart(NULL),
_bufend(NULL),
_datapt(NULL),
_freept(NULL),
- _buffer()
+ _buffer(initial.create(0))
{
assert(_alignment > 0);
if (len > 0) {
// avoid very small buffers for performance reasons:
size_t bufsize = std::max(256ul, roundUp2inN(len + (_alignment - 1)));
- T newBuf(bufsize);
+ Alloc newBuf(initial.create(bufsize));
_bufstart = static_cast<char *>(newBuf.get());
_buffer.swap(newBuf);
@@ -38,18 +37,16 @@ DataBufferT<T>::DataBufferT(size_t len, size_t alignment)
}
-template <typename T>
void
-DataBufferT<T>::moveFreeToData(size_t len)
+DataBuffer::moveFreeToData(size_t len)
{
assert(getFreeLen() >= len);
_freept += len;
}
-template <typename T>
void
-DataBufferT<T>::moveDeadToData(size_t len)
+DataBuffer::moveDeadToData(size_t len)
{
assert(getDeadLen() >= len);
_datapt -= len;
@@ -59,18 +56,16 @@ DataBufferT<T>::moveDeadToData(size_t len)
}
-template <typename T>
void
-DataBufferT<T>::moveDataToFree(size_t len)
+DataBuffer::moveDataToFree(size_t len)
{
assert(getDataLen() >= len);
_freept -= len;
}
-template <typename T>
bool
-DataBufferT<T>::shrink(size_t newsize)
+DataBuffer::shrink(size_t newsize)
{
if (getBufSize() <= newsize || getDataLen() > newsize) {
return false;
@@ -78,7 +73,7 @@ DataBufferT<T>::shrink(size_t newsize)
char *newbuf = NULL;
char *newdata = NULL;
newsize += (_alignment - 1);
- T newBuf(newsize);
+ Alloc newBuf(_buffer.create(newsize));
if (newsize != 0) {
newbuf = static_cast<char *>(newBuf.get());
newdata = newbuf + padbefore(_alignment, newbuf);
@@ -93,9 +88,8 @@ DataBufferT<T>::shrink(size_t newsize)
}
-template <typename T>
void
-DataBufferT<T>::pack(size_t needbytes)
+DataBuffer::pack(size_t needbytes)
{
needbytes += (_alignment - 1);
size_t dataLen = getDataLen();
@@ -104,7 +98,7 @@ DataBufferT<T>::pack(size_t needbytes)
(getDeadLen() + getFreeLen()) * 4 < dataLen)
{
size_t bufsize = std::max(256ul, roundUp2inN(needbytes+dataLen));
- T newBuf(bufsize);
+ Alloc newBuf(_buffer.create(bufsize));
char *newbuf = static_cast<char *>(newBuf.get());
char *newdata = newbuf + padbefore(_alignment, newbuf);
memcpy(newdata, _datapt, dataLen);
@@ -122,9 +116,8 @@ DataBufferT<T>::pack(size_t needbytes)
}
-template <typename T>
bool
-DataBufferT<T>::equals(DataBufferT *other)
+DataBuffer::equals(DataBuffer *other)
{
if (getDataLen() != other->getDataLen())
return false;
@@ -132,9 +125,8 @@ DataBufferT<T>::equals(DataBufferT *other)
}
-template <typename T>
void
-DataBufferT<T>::hexDump()
+DataBuffer::hexDump()
{
char *pt = _datapt;
printf("*** DataBuffer HexDump BEGIN ***\n");
@@ -150,9 +142,8 @@ DataBufferT<T>::hexDump()
}
-template <typename T>
void
-DataBufferT<T>::swap(DataBufferT &other)
+DataBuffer::swap(DataBuffer &other)
{
_buffer.swap(other._buffer);
std::swap(_alignment, other._alignment);
@@ -163,9 +154,8 @@ DataBufferT<T>::swap(DataBufferT &other)
std::swap(_freept, other._freept);
}
-template <typename T>
-T
-DataBufferT<T>::stealBuffer()
+vespalib::alloc::Alloc
+DataBuffer::stealBuffer()
{
assert( ! referencesExternalData() );
_externalBuf = nullptr;
@@ -176,15 +166,9 @@ DataBufferT<T>::stealBuffer()
return std::move(_buffer);
}
-template <typename T>
bool
-DataBufferT<T>::referencesExternalData() const {
+DataBuffer::referencesExternalData() const {
return (_externalBuf == _bufstart) && (getBufSize() > 0);
}
-template class DataBufferT<HeapAlloc>;
-template class DataBufferT<MMapAlloc>;
-template class DataBufferT<DefaultAlloc>;
-
-
} // namespace vespalib
diff --git a/staging_vespalib/src/vespa/vespalib/data/databuffer.h b/staging_vespalib/src/vespa/vespalib/data/databuffer.h
index 7db17808eae..76a604732f5 100644
--- a/staging_vespalib/src/vespa/vespalib/data/databuffer.h
+++ b/staging_vespalib/src/vespa/vespalib/data/databuffer.h
@@ -30,23 +30,23 @@ namespace vespalib {
* the data will be relocated within the buffer and/or a bigger buffer
* will be allocated.
**/
-template <typename T>
-class DataBufferT
+class DataBuffer
{
private:
+ using Alloc = vespalib::alloc::Alloc;
size_t _alignment;
char *_externalBuf;
char *_bufstart;
char *_bufend;
char *_datapt;
char *_freept;
- T _buffer;
+ Alloc _buffer;
- DataBufferT(const DataBufferT &);
- DataBufferT &operator=(const DataBufferT &);
+ DataBuffer(const DataBuffer &);
+ DataBuffer &operator=(const DataBuffer &);
public:
- typedef std::unique_ptr<DataBufferT<T>> UP;
+ typedef std::unique_ptr<DataBuffer> UP;
/**
* Construct a databuffer.
@@ -54,7 +54,7 @@ public:
* @param len the initial size of the buffer.
* @param alignment required memory alignment for data start
**/
- DataBufferT(size_t len = 1024, size_t alignment = 1);
+ DataBuffer(size_t len = 1024, size_t alignment = 1, const Alloc & initial = vespalib::DefaultAlloc::create(0));
/**
* Construct a databuffer using externally allocated memory. Note
@@ -64,22 +64,24 @@ public:
* @param buf pointer to preallocated memory
* @param len length of preallocated memory
**/
- DataBufferT(char *buf, size_t len) :
+ DataBuffer(char *buf, size_t len) :
_alignment(1),
_externalBuf(buf),
_bufstart(buf),
_bufend(buf + len),
_datapt(_bufstart),
- _freept(_bufstart)
+ _freept(_bufstart),
+ _buffer(vespalib::DefaultAlloc::create(0))
{ }
- DataBufferT(const char *buf, size_t len) :
+ DataBuffer(const char *buf, size_t len) :
_alignment(1),
_externalBuf(const_cast<char *>(buf)),
_bufstart(_externalBuf),
_bufend(_bufstart + len),
_datapt(_bufstart),
- _freept(_bufend)
+ _freept(_bufend),
+ _buffer(vespalib::DefaultAlloc::create(0))
{ }
/**
@@ -570,7 +572,7 @@ public:
* @return true(equal)/false(not equal)
* @param other the other buffer.
**/
- bool equals(DataBufferT *other);
+ bool equals(DataBuffer *other);
/**
* Print a human-readable representation of this buffer to
@@ -601,13 +603,10 @@ public:
*
* @param other the other buffer.
**/
- void swap(DataBufferT &other);
+ void swap(DataBuffer &other);
- T stealBuffer();
+ Alloc stealBuffer();
};
-typedef DataBufferT<DefaultAlloc> DataBuffer;
-typedef DataBufferT<MMapAlloc> MMapDataBuffer;
-
} // namespace vespalib
diff --git a/staging_vespalib/src/vespa/vespalib/util/allocinarray.h b/staging_vespalib/src/vespa/vespalib/util/allocinarray.h
index a6a89c4d41a..755d1885eee 100644
--- a/staging_vespalib/src/vespa/vespalib/util/allocinarray.h
+++ b/staging_vespalib/src/vespa/vespalib/util/allocinarray.h
@@ -16,7 +16,7 @@ namespace vespalib {
* - when the AllocInArray goes out of scope.
* - on an explicit clear.
**/
-template <typename T, typename V=vespalib::Array<T, HeapAlloc> >
+template <typename T, typename V=vespalib::Array<T> >
class AllocInArray {
public:
typedef uint32_t Index;
diff --git a/staging_vespalib/src/vespa/vespalib/util/growablebytebuffer.cpp b/staging_vespalib/src/vespa/vespalib/util/growablebytebuffer.cpp
index 96e74ecf007..b17accddc5d 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(initialLen),
+ _buffer(DefaultAlloc::create(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);
- DefaultAlloc newBuf(newSize);
+ Alloc newBuf(DefaultAlloc::create(newSize));
memcpy(newBuf.get(), _buffer.get(), _position);
_buffer.swap(newBuf);
}
diff --git a/staging_vespalib/src/vespa/vespalib/util/growablebytebuffer.h b/staging_vespalib/src/vespa/vespalib/util/growablebytebuffer.h
index 61baa250e40..fd65f0134bc 100644
--- a/staging_vespalib/src/vespa/vespalib/util/growablebytebuffer.h
+++ b/staging_vespalib/src/vespa/vespalib/util/growablebytebuffer.h
@@ -85,8 +85,8 @@ public:
private:
void putReverse(const char* buffer, uint32_t length);
-
- DefaultAlloc _buffer;
+ using Alloc = vespalib::alloc::Alloc;
+ Alloc _buffer;
uint32_t _position;
double _growFactor;
diff --git a/storage/src/vespa/storage/bucketdb/judymultimap.h b/storage/src/vespa/storage/bucketdb/judymultimap.h
index 52f4793aa7c..c6f0194c7bd 100644
--- a/storage/src/vespa/storage/bucketdb/judymultimap.h
+++ b/storage/src/vespa/storage/bucketdb/judymultimap.h
@@ -151,10 +151,10 @@ public:
private:
JudyArray _judyArray;
- typedef vespalib::Array<Type0, vespalib::DefaultAlloc> Type0Vector;
- typedef vespalib::Array<Type1, vespalib::DefaultAlloc> Type1Vector;
- typedef vespalib::Array<Type2, vespalib::DefaultAlloc> Type2Vector;
- typedef vespalib::Array<Type3, vespalib::DefaultAlloc> Type3Vector;
+ typedef vespalib::Array<Type0> Type0Vector;
+ typedef vespalib::Array<Type1> Type1Vector;
+ typedef vespalib::Array<Type2> Type2Vector;
+ typedef vespalib::Array<Type3> Type3Vector;
Type0Vector _values0;
Type1Vector _values1;
Type2Vector _values2;
diff --git a/storageapi/src/vespa/storageapi/mbusprot/storagereply.cpp b/storageapi/src/vespa/storageapi/mbusprot/storagereply.cpp
index b9fde51eaef..0165348968e 100644
--- a/storageapi/src/vespa/storageapi/mbusprot/storagereply.cpp
+++ b/storageapi/src/vespa/storageapi/mbusprot/storagereply.cpp
@@ -4,13 +4,17 @@
#include <vespa/storageapi/mbusprot/storagecommand.h>
+using vespalib::DefaultAlloc;
+using vespalib::alloc::Alloc;
+using vespalib::IllegalStateException;
+
namespace storage {
namespace mbusprot {
StorageReply::StorageReply(const mbus::BlobRef& data,
const ProtocolSerialization& serializer)
: _serializer(&serializer),
- _buffer(data.size()),
+ _buffer(DefaultAlloc::create(data.size())),
_mbusType(0),
_reply()
{
@@ -38,20 +42,16 @@ StorageReply::deserialize() const
StorageReply& reply(const_cast<StorageReply&>(*this));
mbus::Message::UP msg(reply.getMessage());
if (msg.get() == 0) {
- throw vespalib::IllegalStateException(
- "Cannot deserialize storage reply before message have been set",
- VESPA_STRLOC);
+ throw IllegalStateException("Cannot deserialize storage reply before message have been set", VESPA_STRLOC);
}
const StorageCommand* cmd(dynamic_cast<const StorageCommand*>(msg.get()));
reply.setMessage(std::move(msg));
if (cmd == 0) {
- throw vespalib::IllegalStateException(
- "Storage reply get message did not return a storage command",
- VESPA_STRLOC);
+ throw IllegalStateException("Storage reply get message did not return a storage command", VESPA_STRLOC);
}
mbus::BlobRef blobRef(static_cast<char *>(_buffer.get()), _buffer.size());
_reply = _serializer->decodeReply(blobRef, *cmd->getCommand())->getReply();
- vespalib::DefaultAlloc().swap(_buffer);
+ Alloc().swap(_buffer);
}
} // mbusprot
diff --git a/storageapi/src/vespa/storageapi/mbusprot/storagereply.h b/storageapi/src/vespa/storageapi/mbusprot/storagereply.h
index 52f7efc50cc..429833bf08b 100644
--- a/storageapi/src/vespa/storageapi/mbusprot/storagereply.h
+++ b/storageapi/src/vespa/storageapi/mbusprot/storagereply.h
@@ -11,7 +11,7 @@ namespace mbusprot {
class StorageReply : public mbus::Reply, public StorageMessage {
const ProtocolSerialization* _serializer;
- mutable vespalib::DefaultAlloc _buffer;
+ mutable vespalib::alloc::Alloc _buffer;
uint32_t _mbusType;
mutable api::StorageReply::SP _reply;
diff --git a/storageapi/src/vespa/storageapi/message/bucket.h b/storageapi/src/vespa/storageapi/message/bucket.h
index 28b3ba36f30..b47aa01c63e 100644
--- a/storageapi/src/vespa/storageapi/message/bucket.h
+++ b/storageapi/src/vespa/storageapi/message/bucket.h
@@ -409,7 +409,7 @@ public:
: _bucketId(id), _info(info) {}
friend std::ostream& operator<<(std::ostream& os, const Entry&);
};
- typedef vespalib::Array<Entry, vespalib::DefaultAlloc> EntryVector;
+ typedef vespalib::Array<Entry> EntryVector;
private:
EntryVector _buckets;
diff --git a/vespalib/src/tests/alloc/allocate_and_core.cpp b/vespalib/src/tests/alloc/allocate_and_core.cpp
index 2cb4d447fd1..f0a0669eb42 100644
--- a/vespalib/src/tests/alloc/allocate_and_core.cpp
+++ b/vespalib/src/tests/alloc/allocate_and_core.cpp
@@ -1,14 +1,14 @@
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <vespa/vespalib/util/alloc.h>
-using namespace vespalib;
+using namespace vespalib::alloc;
int main(int argc, char *argv[]) {
(void) argc;
(void) argv;
- MMapAlloc small( 0x400000); //4M
+ Alloc small(MMapAllocFactory::create(0x400000)); //4M
memset(small.get(), 0x55, small.size());
- MMapAlloc large(0x4000000); //640M
+ Alloc large(MMapAllocFactory::create(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 e6b22aa9e3f..791ea0cea50 100644
--- a/vespalib/src/vespa/vespalib/data/memorydatastore.cpp
+++ b/vespalib/src/vespa/vespalib/data/memorydatastore.cpp
@@ -3,13 +3,15 @@
namespace vespalib {
-MemoryDataStore::MemoryDataStore(size_t initialSize, Lock * lock) :
+using alloc::Alloc;
+
+MemoryDataStore::MemoryDataStore(Alloc && initialAlloc, Lock * lock) :
_buffers(),
_writePos(0),
_lock(lock)
{
_buffers.reserve(24);
- _buffers.emplace_back(initialSize);
+ _buffers.emplace_back(std::move(initialAlloc));
}
MemoryDataStore::~MemoryDataStore()
@@ -26,7 +28,7 @@ MemoryDataStore::push_back(const void * data, const size_t sz)
const Alloc & b = _buffers.back();
if ((sz + _writePos) > b.size()) {
size_t newSize(std::max(sz, _buffers.back().size()*2));
- _buffers.emplace_back(newSize);
+ _buffers.emplace_back(b.create(newSize));
_writePos = 0;
}
Alloc & buf = _buffers.back();
@@ -39,7 +41,7 @@ MemoryDataStore::push_back(const void * data, const size_t sz)
VariableSizeVector::VariableSizeVector(size_t initialSize) :
_vector(),
- _store(initialSize)
+ _store(DefaultAlloc::create(initialSize))
{
}
diff --git a/vespalib/src/vespa/vespalib/data/memorydatastore.h b/vespalib/src/vespa/vespalib/data/memorydatastore.h
index 3b345cb29bd..b61fa3665ad 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(size_t initialSize=256, Lock * lock=nullptr);
+ MemoryDataStore(alloc::Alloc && initialAlloc=DefaultAlloc::create(256), Lock * lock=nullptr);
MemoryDataStore(const MemoryDataStore &) = delete;
MemoryDataStore & operator = (const MemoryDataStore &) = delete;
~MemoryDataStore();
@@ -38,7 +38,7 @@ public:
_buffers.clear();
}
private:
- std::vector<DefaultAlloc> _buffers;
+ std::vector<alloc::Alloc> _buffers;
size_t _writePos;
Lock * _lock;
};
diff --git a/vespalib/src/vespa/vespalib/objects/nbostream.h b/vespalib/src/vespa/vespalib/objects/nbostream.h
index af5ac47fcb5..cb15db018fc 100644
--- a/vespalib/src/vespa/vespalib/objects/nbostream.h
+++ b/vespalib/src/vespa/vespalib/objects/nbostream.h
@@ -36,7 +36,8 @@ private:
class nbostream
{
public:
- typedef Array<char, DefaultAlloc> Buffer;
+ using Buffer = Array<char>;
+ using Alloc = alloc::Alloc;
enum State { ok=0, eof=0x01};
nbostream(size_t initialSize=1024) :
_wbuf(),
@@ -59,7 +60,7 @@ class nbostream
{
}
- nbostream(DefaultAlloc && buf, size_t sz) :
+ nbostream(Alloc && buf, size_t sz) :
_wbuf(std::move(buf), sz),
_rbuf(&_wbuf[0], sz),
_rp(0),
diff --git a/vespalib/src/vespa/vespalib/stllike/hashtable.h b/vespalib/src/vespa/vespalib/stllike/hashtable.h
index e038c9f40d9..a1eeb289c31 100644
--- a/vespalib/src/vespa/vespalib/stllike/hashtable.h
+++ b/vespalib/src/vespa/vespalib/stllike/hashtable.h
@@ -132,7 +132,7 @@ class hashtable : public hashtable_base
private:
using Node=hash_node<Value>;
protected:
- typedef vespalib::Array<Node, vespalib::DefaultAlloc > NodeStore;
+ typedef vespalib::Array<Node> NodeStore;
virtual void move(NodeStore && oldStore);
public:
class const_iterator;
diff --git a/vespalib/src/vespa/vespalib/util/alloc.cpp b/vespalib/src/vespa/vespalib/util/alloc.cpp
index 552ac547dae..d719d7386bb 100644
--- a/vespalib/src/vespa/vespalib/util/alloc.cpp
+++ b/vespalib/src/vespa/vespalib/util/alloc.cpp
@@ -88,11 +88,11 @@ alloc::HeapAllocator _G_heapAllocatorDefault;
alloc::AlignedHeapAllocator _G_4KalignedHeapAllocator(4096);
alloc::AlignedHeapAllocator _G_512BalignedHeapAllocator(512);
alloc::MMapAllocator _G_mmapAllocatorDefault;
-alloc::AutoAllocator _G_autoAllocatorDefault(alloc::MMapAllocator::HUGEPAGE_SIZE);
-alloc::AutoAllocator _G_2PautoAllocatorDefault(2 * alloc::MMapAllocator::HUGEPAGE_SIZE);
-alloc::AutoAllocator _G_4PautoAllocatorDefault(4 * alloc::MMapAllocator::HUGEPAGE_SIZE);
-alloc::AutoAllocator _G_8PautoAllocatorDefault(8 * alloc::MMapAllocator::HUGEPAGE_SIZE);
-alloc::AutoAllocator _G_16PautoAllocatorDefault(16 * alloc::MMapAllocator::HUGEPAGE_SIZE);
+alloc::AutoAllocator _G_autoAllocatorDefault(alloc::MMapAllocator::HUGEPAGE_SIZE, 0);
+alloc::AutoAllocator _G_2PautoAllocatorDefault(2 * alloc::MMapAllocator::HUGEPAGE_SIZE, 0);
+alloc::AutoAllocator _G_4PautoAllocatorDefault(4 * alloc::MMapAllocator::HUGEPAGE_SIZE, 0);
+alloc::AutoAllocator _G_8PautoAllocatorDefault(8 * alloc::MMapAllocator::HUGEPAGE_SIZE, 0);
+alloc::AutoAllocator _G_16PautoAllocatorDefault(16 * alloc::MMapAllocator::HUGEPAGE_SIZE, 0);
}
@@ -134,7 +134,7 @@ MemoryAllocator & AutoAllocator::get16P() {
return _G_16PautoAllocatorDefault;
}
-void * HeapAllocator::alloc(size_t sz) {
+void * HeapAllocator::alloc(size_t sz) const {
return salloc(sz);
}
@@ -142,7 +142,7 @@ void * HeapAllocator::salloc(size_t sz) {
return (sz > 0) ? malloc(sz) : 0;
}
-void HeapAllocator::free(void * p, size_t sz) {
+void HeapAllocator::free(void * p, size_t sz) const {
sfree(p, sz);
}
@@ -150,19 +150,17 @@ void HeapAllocator::sfree(void * p, size_t sz) {
(void) sz; if (p) { ::free(p); }
}
-void * AlignedHeapAllocator::alloc(size_t sz) {
+void * AlignedHeapAllocator::alloc(size_t sz) const {
if (!sz) { return 0; }
void* ptr;
int result = posix_memalign(&ptr, _alignment, sz);
if (result != 0) {
- throw IllegalArgumentException(
- make_string("posix_memalign(%zu, %zu) failed with code %d",
- sz, _alignment, result));
+ throw IllegalArgumentException(make_string("posix_memalign(%zu, %zu) failed with code %d", sz, _alignment, result));
}
return ptr;
}
-void * MMapAllocator::alloc(size_t sz) {
+void * MMapAllocator::alloc(size_t sz) const {
return salloc(sz);
}
@@ -217,7 +215,7 @@ void * MMapAllocator::salloc(size_t sz)
return buf;
}
-void MMapAllocator::free(void * buf, size_t sz) {
+void MMapAllocator::free(void * buf, size_t sz) const {
sfree(buf, sz);
}
@@ -236,16 +234,20 @@ void MMapAllocator::sfree(void * buf, size_t sz)
}
}
-void * AutoAllocator::alloc(size_t sz) {
+void * AutoAllocator::alloc(size_t sz) const {
if (useMMap(sz)) {
sz = roundUpToHugePages(sz);
return MMapAllocator::salloc(sz);
} else {
- return HeapAllocator::salloc(sz);
+ if (_alignment == 0) {
+ return HeapAllocator::salloc(sz);
+ } else {
+ return AlignedHeapAllocator(_alignment).alloc(sz);
+ }
}
}
-void AutoAllocator::free(void *p, size_t sz) {
+void AutoAllocator::free(void *p, size_t sz) const {
if (useMMap(sz)) {
return MMapAllocator::sfree(p, sz);
} else {
@@ -253,5 +255,32 @@ void AutoAllocator::free(void *p, size_t sz) {
}
}
+Alloc
+MMapAllocFactory::create(size_t sz)
+{
+ return Alloc(&MMapAllocator::getDefault(), sz);
}
+
+Alloc
+AutoAllocFactory::create(size_t sz, size_t mmapLimit, size_t alignment)
+{
+ if (alignment == 0) {
+ if (mmapLimit <= MMapAllocator::HUGEPAGE_SIZE) {
+ return Alloc(&AutoAllocator::getDefault(), sz);
+ } else if (mmapLimit <= 2*MMapAllocator::HUGEPAGE_SIZE) {
+ return Alloc(&AutoAllocator::get2P(), sz);
+ } else if (mmapLimit <= 4*MMapAllocator::HUGEPAGE_SIZE) {
+ return Alloc(&AutoAllocator::get4P(), sz);
+ } else if (mmapLimit <= 8*MMapAllocator::HUGEPAGE_SIZE) {
+ return Alloc(&AutoAllocator::get8P(), sz);
+ } else {
+ return Alloc(&AutoAllocator::get16P(), sz);
+ }
+ } else {
+ abort();
+ }
+}
+
+}
+
}
diff --git a/vespalib/src/vespa/vespalib/util/alloc.h b/vespalib/src/vespa/vespalib/util/alloc.h
index 6cb70ee5f55..23f4923b3c5 100644
--- a/vespalib/src/vespa/vespalib/util/alloc.h
+++ b/vespalib/src/vespa/vespalib/util/alloc.h
@@ -17,14 +17,14 @@ public:
MemoryAllocator & operator = (const MemoryAllocator &) = delete;
MemoryAllocator() { }
virtual ~MemoryAllocator() { }
- virtual void * alloc(size_t sz) = 0;
- virtual void free(void * buf, size_t sz) = 0;
+ virtual void * alloc(size_t sz) const = 0;
+ virtual void free(void * buf, size_t sz) const = 0;
};
class HeapAllocator : public MemoryAllocator {
public:
- void * alloc(size_t sz) override;
- void free(void * buf, size_t sz) override;
+ void * alloc(size_t sz) const override;
+ void free(void * buf, size_t sz) const override;
static void * salloc(size_t sz);
static void sfree(void * buf, size_t sz);
static MemoryAllocator & getDefault();
@@ -33,7 +33,7 @@ public:
class AlignedHeapAllocator : public HeapAllocator {
public:
AlignedHeapAllocator(size_t alignment) : _alignment(alignment) { }
- void * alloc(size_t sz) override;
+ void * alloc(size_t sz) const override;
static MemoryAllocator & get4K();
static MemoryAllocator & get512B();
private:
@@ -43,8 +43,8 @@ private:
class MMapAllocator : public MemoryAllocator {
public:
enum {HUGEPAGE_SIZE=0x200000};
- void * alloc(size_t sz) override;
- void free(void * buf, size_t sz) override;
+ void * alloc(size_t sz) const override;
+ void free(void * buf, size_t sz) const override;
static void * salloc(size_t sz);
static void sfree(void * buf, size_t sz);
static size_t roundUpToHugePages(size_t sz) {
@@ -55,35 +55,35 @@ public:
class AutoAllocator : public MemoryAllocator {
public:
- AutoAllocator(size_t mmapLimit) : _mmapLimit(mmapLimit) { }
- void * alloc(size_t sz) override;
- void free(void * buf, size_t sz) override;
+ AutoAllocator(size_t mmapLimit, size_t alignment) : _mmapLimit(mmapLimit), _alignment(alignment) { }
+ void * alloc(size_t sz) const override;
+ void free(void * buf, size_t sz) const override;
static MemoryAllocator & getDefault();
static MemoryAllocator & get2P();
static MemoryAllocator & get4P();
static MemoryAllocator & get8P();
static MemoryAllocator & get16P();
private:
- size_t roundUpToHugePages(size_t sz) {
+ size_t roundUpToHugePages(size_t sz) const {
return (_mmapLimit >= MMapAllocator::HUGEPAGE_SIZE)
? MMapAllocator::roundUpToHugePages(sz)
: sz;
}
- bool useMMap(size_t sz) { return (sz >= _mmapLimit); }
+ bool useMMap(size_t sz) const { return (sz >= _mmapLimit); }
size_t _mmapLimit;
+ size_t _alignment;
};
-}
-inline size_t roundUp2inN(size_t minimum) {
- return 2ul << Optimized::msbIdx(minimum - 1);
-}
/**
- * This is an allocated buffer interface that does not accept virtual inheritance.
+ * This represents an allocation.
+ * It can be created, moved, swapped and resized.
+ * The allocation strategy is decided upon creation.
**/
class Alloc
{
public:
+ using MemoryAllocator = alloc::MemoryAllocator;
size_t size() const { return _sz; }
void * get() { return _buf; }
const void * get() const { return _buf; }
@@ -91,107 +91,66 @@ public:
const void * operator -> () const { return _buf; }
Alloc(const Alloc &) = delete;
Alloc & operator = (const Alloc &) = delete;
-protected:
Alloc(Alloc && rhs) :
_buf(rhs._buf),
- _sz(rhs._sz)
+ _sz(rhs._sz),
+ _allocator(rhs._allocator)
{
rhs._buf = nullptr;
rhs._sz = 0;
+ rhs._allocator = 0;
}
Alloc & operator=(Alloc && rhs) {
if (this != & rhs) {
- internalSwap(rhs);
+ swap(rhs);
}
return *this;
}
- Alloc(void * buf, size_t sz) : _buf(buf), _sz(sz) { }
- ~Alloc() { _buf = 0; }
- void internalSwap(Alloc & rhs) {
+ Alloc() : _buf(nullptr), _sz(0), _allocator(nullptr) { }
+ Alloc(const MemoryAllocator * allocator, size_t sz) : _buf(allocator->alloc(sz)), _sz(sz), _allocator(allocator) { }
+ ~Alloc() {
+ if (_buf != nullptr) {
+ _allocator->free(_buf, _sz);
+ _buf = nullptr;
+ }
+ }
+ void swap(Alloc & rhs) {
std::swap(_buf, rhs._buf);
std::swap(_sz, rhs._sz);
+ std::swap(_allocator, rhs._allocator);
}
-private:
- void * _buf;
- size_t _sz;
+ Alloc create(size_t sz) const {
+ return Alloc(_allocator, sz);
+ }
+protected:
+ void alloc(const MemoryAllocator * allocator, size_t sz) {
+ assert(_buf == nullptr);
+ _allocator = allocator;
+ _sz = sz;
+ _buf = allocator->alloc(sz);
+ }
+ void * _buf;
+ size_t _sz;
+ const MemoryAllocator * _allocator;
};
-class HeapAlloc : public Alloc
+class HeapAllocFactory
{
public:
- typedef std::unique_ptr<HeapAlloc> UP;
- HeapAlloc() : Alloc(NULL, 0) { }
- HeapAlloc(size_t sz) : Alloc(HeapAlloc::alloc(sz), sz) { }
- ~HeapAlloc() { HeapAlloc::free(get(), size()); }
- HeapAlloc(HeapAlloc && rhs) : Alloc(std::move(rhs)) { }
-
- HeapAlloc & operator=(HeapAlloc && rhs) {
- Alloc::operator=(std::move(rhs));
- return *this;
- }
- void swap(HeapAlloc & rhs) { internalSwap(rhs); }
-public:
- static void * alloc(size_t sz) { return alloc::HeapAllocator::getDefault().alloc(sz); }
- static void free(void * buf, size_t sz) { alloc::HeapAllocator::getDefault().free(buf, sz); }
+ static Alloc create(size_t sz=0);
};
-class AlignedHeapAlloc : public Alloc
+class AlignedHeapAllocFactory
{
public:
- typedef std::unique_ptr<AlignedHeapAlloc> UP;
- AlignedHeapAlloc() : Alloc(NULL, 0) { }
- AlignedHeapAlloc(size_t sz, size_t alignment)
- : Alloc(AlignedHeapAlloc::alloc(sz, alignment), sz) { }
- AlignedHeapAlloc(AlignedHeapAlloc && rhs) : Alloc(std::move(rhs)) { }
-
- AlignedHeapAlloc & operator=(AlignedHeapAlloc && rhs) {
- Alloc::operator=(std::move(rhs));
- return *this;
- }
- ~AlignedHeapAlloc() { AlignedHeapAlloc::free(get(), size()); }
- void swap(AlignedHeapAlloc & rhs) { internalSwap(rhs); }
-public:
- static void * alloc(size_t sz, size_t alignment) { return alloc::AlignedHeapAllocator(alignment).alloc(sz); }
- static void free(void * buf, size_t sz) { return alloc::AlignedHeapAllocator(0).free(buf, sz); }
+ static Alloc create(size_t sz, size_t alignment);
};
-
-class MMapAlloc : public Alloc
+class MMapAllocFactory
{
public:
enum {HUGEPAGE_SIZE=0x200000};
- typedef std::unique_ptr<MMapAlloc> UP;
- MMapAlloc() : Alloc(NULL, 0) { }
- MMapAlloc(size_t sz) : Alloc(MMapAlloc::alloc(sz), sz) { }
- MMapAlloc(MMapAlloc && rhs) : Alloc(std::move(rhs)) { }
-
- MMapAlloc & operator=(MMapAlloc && rhs) {
- Alloc::operator=(std::move(rhs));
- return *this;
- }
- ~MMapAlloc() { MMapAlloc::free(get(), size()); }
- void swap(MMapAlloc & rhs) { internalSwap(rhs); }
-public:
- static void * alloc(size_t sz) { return alloc::MMapAllocator::getDefault().alloc(sz); }
- static void free(void * buf, size_t sz) { alloc::MMapAllocator::getDefault().free(buf, sz); }
-};
-
-// Alignment requirement is != 0, use posix_memalign
-template <size_t Alignment>
-struct ChooseHeapAlloc
-{
- static inline void* alloc(size_t sz) {
- return AlignedHeapAlloc::alloc(sz, Alignment);
- }
-};
-
-// No alignment required, use regular malloc
-template <>
-struct ChooseHeapAlloc<0>
-{
- static inline void* alloc(size_t sz) {
- return HeapAlloc::alloc(sz);
- }
+ static Alloc create(size_t sz=0);
};
/**
@@ -199,53 +158,19 @@ struct ChooseHeapAlloc<0>
* is always used when size is above limit.
*/
-template <size_t Lim=MMapAlloc::HUGEPAGE_SIZE, size_t Alignment=0>
-class AutoAlloc : public Alloc
+class AutoAllocFactory
{
public:
- typedef std::unique_ptr<AutoAlloc> UP;
- typedef vespalib::LinkedPtr<AutoAlloc> LP;
- AutoAlloc() : Alloc(NULL, 0) { }
- AutoAlloc(size_t sz)
- : Alloc(useMMap(sz)
- ? MMapAlloc::alloc(roundUpToHugePages(sz))
- : ChooseHeapAlloc<Alignment>::alloc(sz),
- useMMap(sz)
- ? roundUpToHugePages(sz)
- : sz)
- { }
- AutoAlloc(AutoAlloc && rhs) : Alloc(std::move(rhs)) { }
-
- AutoAlloc & operator=(AutoAlloc && rhs) {
- Alloc::operator=(std::move(rhs));
- return *this;
- }
-
- ~AutoAlloc() {
- if (useMMap(size())) {
- MMapAlloc::free(get(), size());
- } else {
- HeapAlloc::free(get(), size());
- }
- }
- void swap(AutoAlloc & rhs) { internalSwap(rhs); }
-private:
- static size_t roundUpToHugePages(size_t sz) {
- return (Lim >= MMapAlloc::HUGEPAGE_SIZE)
- ? (sz+(MMapAlloc::HUGEPAGE_SIZE-1)) & ~(MMapAlloc::HUGEPAGE_SIZE-1)
- : sz;
- }
- static bool useMMap(size_t sz) { return (sz >= Lim); }
+ static Alloc create(size_t sz=0, size_t mmapLimit=MMapAllocator::HUGEPAGE_SIZE, size_t alignment=0);
};
-template <size_t Lim>
-inline void swap(AutoAlloc<Lim> & a, AutoAlloc<Lim> & b) { a.swap(b); }
+}
-inline void swap(HeapAlloc & a, HeapAlloc & b) { a.swap(b); }
-inline void swap(AlignedHeapAlloc & a, AlignedHeapAlloc & b) { a.swap(b); }
-inline void swap(MMapAlloc & a, MMapAlloc & b) { a.swap(b); }
+inline size_t roundUp2inN(size_t minimum) {
+ return 2ul << Optimized::msbIdx(minimum - 1);
+}
-typedef AutoAlloc<> DefaultAlloc;
+using DefaultAlloc = alloc::AutoAllocFactory;
}
diff --git a/vespalib/src/vespa/vespalib/util/array.h b/vespalib/src/vespa/vespalib/util/array.h
index 8f40d4de0c7..f2546e46e22 100644
--- a/vespalib/src/vespa/vespalib/util/array.h
+++ b/vespalib/src/vespa/vespalib/util/array.h
@@ -35,7 +35,7 @@ private:
* it generates more efficient code.
* It only supports simple objects without constructors/destructors.
**/
-template <typename T, typename B=HeapAlloc>
+template <typename T>
class Array {
public:
class reverse_iterator {
@@ -101,18 +101,19 @@ public:
friend size_t operator -(const_reverse_iterator a, const_reverse_iterator b) { return b._p - a._p; }
const T * _p;
};
+ using Alloc = alloc::Alloc;
typedef const T * const_iterator;
typedef T * iterator;
typedef const T & const_reference;
typedef T value_type;
typedef size_t size_type;
- Array() : _array(), _sz(0) { }
- Array(size_t sz);
- Array(B && buf, size_t sz);
+ Array(const Alloc & initial=DefaultAlloc::create()) : _array(initial.create(0)), _sz(0) { }
+ Array(size_t sz, const Alloc & initial=DefaultAlloc::create());
+ Array(Alloc && buf, size_t sz);
Array(Array &&rhs);
- Array(size_t sz, T value);
- Array(const_iterator begin, const_iterator end);
+ Array(size_t sz, T value, const Alloc & initial=DefaultAlloc::create());
+ Array(const_iterator begin, const_iterator end, const Alloc & initial=DefaultAlloc::create());
Array(const Array & rhs);
Array & operator =(const Array & rhs) {
if (&rhs != this) {
@@ -185,7 +186,7 @@ private:
reserve(roundUp2inN(n));
}
}
- B _array;
+ Alloc _array;
size_t _sz;
};
@@ -236,16 +237,16 @@ void construct(T * dest, size_t sz, T val, std::tr1::true_type)
}
}
-template <typename T, typename B>
-Array<T, B>::Array(const Array & rhs)
- : _array(rhs.size() * sizeof(T)),
+template <typename T>
+Array<T>::Array(const Array & rhs)
+ : _array(rhs._array.create(rhs.size() * sizeof(T))),
_sz(rhs.size())
{
construct(array(0), rhs.array(0), _sz, std::tr1::has_trivial_destructor<T>());
}
-template <typename T, typename B>
-bool Array<T, B>::operator ==(const Array & rhs) const
+template <typename T>
+bool Array<T>::operator ==(const Array & rhs) const
{
bool retval(size() == rhs.size());
for (size_t i(0); retval && (i < _sz); i++) {
@@ -256,8 +257,8 @@ bool Array<T, B>::operator ==(const Array & rhs) const
return retval;
}
-template <typename T, typename B>
-void Array<T, B>::resize(size_t n)
+template <typename T>
+void Array<T>::resize(size_t n)
{
if (n > capacity()) {
reserve(n);
@@ -285,69 +286,68 @@ void move(T * dest, const T * source, size_t sz, std::tr1::true_type)
memcpy(dest, source, sz*sizeof(T));
}
-template <typename T, typename B>
-void Array<T, B>::increase(size_t n)
+template <typename T>
+void Array<T>::increase(size_t n)
{
- B newArray(sizeof(T)*n);
+ Alloc newArray(_array.create(sizeof(T)*n));
if (capacity() > 0) {
move(static_cast<T *>(newArray.get()), array(0), _sz, std::tr1::has_trivial_destructor<T>());
}
_array.swap(newArray);
}
-template <typename T, typename B>
-Array<T, B>::Array(B && buf, size_t sz) :
+template <typename T>
+Array<T>::Array(Alloc && buf, size_t sz) :
_array(std::move(buf)),
_sz(sz)
{
}
-template <typename T, typename B>
-Array<T, B>::Array(Array &&rhs)
+template <typename T>
+Array<T>::Array(Array &&rhs)
: _array(std::move(rhs._array)),
_sz(rhs._sz)
{
rhs._sz = 0;
}
-template <typename T, typename B>
-Array<T, B>::Array(size_t sz) :
- _array(sz * sizeof(T)),
+template <typename T>
+Array<T>::Array(size_t sz, const Alloc & initial) :
+ _array(initial.create(sz * sizeof(T))),
_sz(sz)
{
construct(array(0), _sz, std::tr1::has_trivial_destructor<T>());
}
-template <typename T, typename B>
-Array<T, B>::Array(size_t sz, T value) :
- _array(sz * sizeof(T)),
+template <typename T>
+Array<T>::Array(size_t sz, T value, const Alloc & initial) :
+ _array(initial.create(sz * sizeof(T))),
_sz(sz)
{
construct(array(0), _sz, value, std::tr1::has_trivial_destructor<T>());
}
-template <typename T, typename B>
-Array<T, B>::Array(const_iterator begin_, const_iterator end_) :
- _array(begin_ != end_ ? sizeof(T) * (end_-begin_) : 0),
+template <typename T>
+Array<T>::Array(const_iterator begin_, const_iterator end_, const Alloc & initial) :
+ _array(initial.create(begin_ != end_ ? sizeof(T) * (end_-begin_) : 0)),
_sz(end_-begin_)
{
construct(array(0), begin_, _sz, std::tr1::has_trivial_destructor<T>());
}
-template <typename T, typename B>
-Array<T, B>::~Array()
+template <typename T>
+Array<T>::~Array()
{
cleanup();
}
-template <typename T, typename B>
-void Array<T, B>::cleanup()
+template <typename T>
+void Array<T>::cleanup()
{
std::_Destroy(array(0), array(_sz));
_sz = 0;
- B tmp;
- tmp.swap(_array);
+ Alloc().swap(_array);
}
}
diff --git a/vsm/src/vespa/vsm/searcher/fieldsearcher.h b/vsm/src/vespa/vsm/searcher/fieldsearcher.h
index 597baea1b67..73ad8a9f28a 100644
--- a/vsm/src/vespa/vsm/searcher/fieldsearcher.h
+++ b/vsm/src/vespa/vsm/searcher/fieldsearcher.h
@@ -18,7 +18,7 @@ typedef size_t termsize_t;
#endif
typedef ucs4_t cmptype_t;
-typedef vespalib::Array<cmptype_t, vespalib::DefaultAlloc> SearcherBuf;
+typedef vespalib::Array<cmptype_t> SearcherBuf;
typedef std::shared_ptr<SearcherBuf> SharedSearcherBuf;
typedef std::vector<char> CharVector;