diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2010-07-26 15:40:44 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2010-07-26 15:40:44 +0200 |
commit | 33e33d260dddd6adb226814415811926c1a779ae (patch) | |
tree | 20f718398ba5bb118d2e27e4c3de35fe8ea4fe80 /odb/buffer.cxx | |
parent | 32f1168489c12677fbb174c5119b5edd40309b79 (diff) |
Buffer implementation
Diffstat (limited to 'odb/buffer.cxx')
-rw-r--r-- | odb/buffer.cxx | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/odb/buffer.cxx b/odb/buffer.cxx new file mode 100644 index 0000000..f920258 --- /dev/null +++ b/odb/buffer.cxx @@ -0,0 +1,34 @@ +// file : odb/buffer.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#include <cstring> // std::memcpy + +#include <odb/buffer.hxx> + +using namespace std; + +namespace odb +{ + void buffer:: + capacity (size_t c, size_t data_size) + { + if (c > capacity_) + { + size_t n (capacity_ * 2 > c ? capacity_ * 2 : c); + char* d (static_cast<char*> (operator new (n))); + + if (data_ != 0) + { + if (data_size != 0) + memcpy (d, data_, data_size); + + operator delete (data_); + } + + data_ = d; + capacity_ = n; + } + } +} |