Track the requested size yourself as the underlying allocation will take the liberty of rounding up to a suitable pagesize.
@@ -77,11 +77,11 @@ public:
typedef vespalib::LinkedPtr<SharedBuffer> LP;
explicit SharedBuffer(size_t totalSize)
: _buf(vespalib::alloc::Alloc::allocMMap(totalSize)),
+ _totalSize(totalSize),
_usedSize(0)
- {
- }
+ { }
- size_t getSize() const { return _buf.size(); }
+ size_t getSize() const { return _totalSize; }
size_t getUsedSize() const { return _usedSize; }
size_t getFreeSize() const { return getSize() - getUsedSize(); }
bool hasRoomFor(size_t sz, Alignment align = NO_ALIGN) const {
@@ -115,6 +115,7 @@ public:
}
private:
vespalib::alloc::Alloc _buf;
+ size_t _totalSize;
size_t _usedSize;
};
@@ -159,8 +160,7 @@ public:
HeaderChunkEncoder(const document::DocumentId& docId)
: _serializedDoc(DEFAULT_STREAM_ALLOC_SIZE),
_docId(docId.toString())
- {
- }
+ { }
/**
* Serializes header chunk to buf, which must have at least a size
