diff options
author | Brent Eagles <brent@zeroc.com> | 2006-09-13 11:05:43 +0000 |
---|---|---|
committer | Brent Eagles <brent@zeroc.com> | 2006-09-13 11:05:43 +0000 |
commit | d05310f424bbfb80c53b8697663f949f96c9a261 (patch) | |
tree | fa6988b1319ea7d6d0fd1b7407cb2763923de6ca /cpp/src/Ice/Buffer.cpp | |
parent | Fixes (diff) | |
download | ice-d05310f424bbfb80c53b8697663f949f96c9a261.tar.bz2 ice-d05310f424bbfb80c53b8697663f949f96c9a261.tar.xz ice-d05310f424bbfb80c53b8697663f949f96c9a261.zip |
- Updating Ice and library verison to 3.2.
- Adding memory pool implementation. Enabled by default.
- Added disablePool option to test suite to run tests without the pool.
- Added Ice.MemoryPool and Ice.HighWaterMark properties.
Diffstat (limited to 'cpp/src/Ice/Buffer.cpp')
-rw-r--r-- | cpp/src/Ice/Buffer.cpp | 100 |
1 files changed, 40 insertions, 60 deletions
diff --git a/cpp/src/Ice/Buffer.cpp b/cpp/src/Ice/Buffer.cpp index a841d822422..dc8a6595827 100644 --- a/cpp/src/Ice/Buffer.cpp +++ b/cpp/src/Ice/Buffer.cpp @@ -9,6 +9,7 @@ #include <Ice/Buffer.h> #include <Ice/LocalException.h> +#include <Ice/MemoryPool.h> using namespace std; using namespace Ice; @@ -17,54 +18,34 @@ using namespace IceInternal; void IceInternal::Buffer::swap(Buffer& other) { -#ifdef ICE_SMALL_MESSAGE_BUFFER_OPTIMIZATION - Container::difference_type pos = i - b.begin(); - Container::difference_type otherPos = other.i - other.b.begin(); - b.swap(other.b); - i = b.begin() + otherPos; - other.i = other.b.begin() + pos; -#else b.swap(other.b); std::swap(i, other.i); -#endif } -void -IceInternal::Buffer::Container::swap(Container& other) +IceInternal::Buffer::Container::Container(IceInternal::MemoryPool* pool) : + _buf(0), + _size(0), + _capacity(0), + _pool(pool) +{ +} + +IceInternal::Buffer::Container::~Container() { -#ifdef ICE_SMALL_MESSAGE_BUFFER_OPTIMIZATION - if(_buf == _fixed) + if(_pool) { - if(other._buf == other._fixed) - { - value_type tmp[ICE_BUFFER_FIXED_SIZE]; - memcpy(tmp, _fixed, _size); - memcpy(_fixed, other._fixed, other._size); - memcpy(other._fixed, tmp, _size); - } - else - { - _buf = other._buf; - memcpy(other._fixed, _fixed, _size); - other._buf = other._fixed; - } + _pool->free(_buf); } else { - if(other._buf == other._fixed) - { - other._buf = _buf; - memcpy(_fixed, other._fixed, other._size); - _buf = _fixed; - } - else - { - std::swap(_buf, other._buf); - } + ::free(_buf); } -#else +} + +void +IceInternal::Buffer::Container::swap(Container& other) +{ std::swap(_buf, other._buf); -#endif std::swap(_size, other._size); std::swap(_capacity, other._capacity); @@ -74,20 +55,17 @@ IceInternal::Buffer::Container::swap(Container& other) void IceInternal::Buffer::Container::clear() { -#ifdef ICE_SMALL_MESSAGE_BUFFER_OPTIMIZATION - if(_buf != _fixed) + if(_pool) { - free(_buf); - _buf = _fixed; + _pool->free(_buf); + } + else + { + ::free(_buf); } - _size = 0; - _capacity = ICE_BUFFER_FIXED_SIZE; -#else - free(_buf); _buf = 0; _size = 0; _capacity = 0; -#endif } void @@ -107,26 +85,28 @@ IceInternal::Buffer::Container::reserve(size_type n) return; } -#ifdef ICE_SMALL_MESSAGE_BUFFER_OPTIMIZATION - if(_buf != _fixed) - { - _buf = reinterpret_cast<pointer>(realloc(_buf, _capacity)); - } - else if(_capacity > ICE_BUFFER_FIXED_SIZE) - { - _buf = reinterpret_cast<pointer>(malloc(_capacity)); - memcpy(_buf, _fixed, _size); - } -#else if(_buf) { - _buf = reinterpret_cast<pointer>(realloc(_buf, _capacity)); + if(_pool) + { + _buf = _pool->realloc(_buf, _capacity); + } + else + { + _buf = reinterpret_cast<pointer>(::realloc(_buf, _capacity)); + } } else { - _buf = reinterpret_cast<pointer>(malloc(_capacity)); + if(_pool) + { + _buf = _pool->alloc(_capacity); + } + else + { + _buf = reinterpret_cast<pointer>(::malloc(_capacity)); + } } -#endif if(!_buf) { |