summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cpp/unpack.cpp9
-rw-r--r--cpp/unpack.hpp11
2 files changed, 10 insertions, 10 deletions
diff --git a/cpp/unpack.cpp b/cpp/unpack.cpp
index ea4d414..8edf407 100644
--- a/cpp/unpack.cpp
+++ b/cpp/unpack.cpp
@@ -178,13 +178,14 @@ private:
};
-unpacker::unpacker() :
+unpacker::unpacker(size_t initial_buffer_size) :
m_buffer(NULL),
m_used(0),
m_free(0),
m_off(0),
m_zone(new zone()),
- m_ctx(new context(&*m_zone))
+ m_ctx(new context(&*m_zone)),
+ m_initial_buffer_size(initial_buffer_size)
{ }
@@ -199,14 +200,14 @@ void unpacker::expand_buffer(size_t len)
if(m_off == 0) {
size_t next_size;
if(m_used != 0) { next_size = (m_used + m_free) * 2; }
- else { next_size = UNPACKER_INITIAL_BUFFER_SIZE; }
+ else { next_size = m_initial_buffer_size; }
while(next_size < len + m_used) { next_size *= 2; }
m_buffer = m_zone->realloc(m_buffer, next_size);
m_free = next_size - m_used;
} else {
- size_t next_size = UNPACKER_INITIAL_BUFFER_SIZE;
+ size_t next_size = m_initial_buffer_size;
while(next_size < len + m_used - m_off) { next_size *= 2; }
char* tmp = m_zone->malloc(next_size);
diff --git a/cpp/unpack.hpp b/cpp/unpack.hpp
index ffee60d..ac20de3 100644
--- a/cpp/unpack.hpp
+++ b/cpp/unpack.hpp
@@ -23,16 +23,13 @@
#include <memory>
#include <stdexcept>
-#ifndef MSGPACK_UNPACKER_INITIAL_BUFFER_SIZE
-#define MSGPACK_UNPACKER_INITIAL_BUFFER_SIZE 8*1024
+#ifndef MSGPACK_UNPACKER_DEFAULT_INITIAL_BUFFER_SIZE
+#define MSGPACK_UNPACKER_DEFAULT_INITIAL_BUFFER_SIZE 8*1024
#endif
namespace msgpack {
-static const size_t UNPACKER_INITIAL_BUFFER_SIZE = MSGPACK_UNPACKER_INITIAL_BUFFER_SIZE;
-
-
struct unpack_error : public std::runtime_error {
unpack_error(const std::string& msg) :
std::runtime_error(msg) { }
@@ -41,7 +38,7 @@ struct unpack_error : public std::runtime_error {
class unpacker {
public:
- unpacker();
+ unpacker(size_t initial_buffer_size = MSGPACK_UNPACKER_DEFAULT_INITIAL_BUFFER_SIZE);
~unpacker();
public:
@@ -139,6 +136,8 @@ private:
struct context;
context* m_ctx;
+ const size_t m_initial_buffer_size;
+
private:
void expand_buffer(size_t len);