summaryrefslogtreecommitdiff
path: root/cppe/src
diff options
context:
space:
mode:
authorBenoit Foucher <benoit@zeroc.com>2006-03-02 09:32:09 +0000
committerBenoit Foucher <benoit@zeroc.com>2006-03-02 09:32:09 +0000
commit6229320ae6c0d72ca4d5e6230050f7fc9a92030e (patch)
tree33d2f69e9d27b13e405a27f4918fae4cdf1e395d /cppe/src
parent- Fixes for Windows shutdown issue. (diff)
downloadice-6229320ae6c0d72ca4d5e6230050f7fc9a92030e.tar.bz2
ice-6229320ae6c0d72ca4d5e6230050f7fc9a92030e.tar.xz
ice-6229320ae6c0d72ca4d5e6230050f7fc9a92030e.zip
Shrink the buffer memory if it's not needed anymore.
Diffstat (limited to 'cppe/src')
-rw-r--r--cppe/src/IceE/Buffer.cpp88
-rwxr-xr-xcppe/src/IceE/Connection.cpp2
2 files changed, 54 insertions, 36 deletions
diff --git a/cppe/src/IceE/Buffer.cpp b/cppe/src/IceE/Buffer.cpp
index fc262441bea..da5aaabd742 100644
--- a/cppe/src/IceE/Buffer.cpp
+++ b/cppe/src/IceE/Buffer.cpp
@@ -71,48 +71,66 @@ IceInternal::Buffer::Container::swap(Container& other)
}
void
-IceInternal::Buffer::Container::resizeImpl(size_type n)
+IceInternal::Buffer::Container::clear()
{
- if(n == 0)
+#ifdef ICE_SMALL_MESSAGE_BUFFER_OPTIMIZATION
+ if(_buf != _fixed)
{
- clear();
+ free(_buf);
+ _buf = _fixed;
+ }
+ _size = 0;
+ _capacity = ICE_BUFFER_FIXED_SIZE;
+#else
+ free(_buf);
+ _buf = 0;
+ _size = 0;
+ _capacity = 0;
+#endif
+}
+
+void
+IceInternal::Buffer::Container::reserve(size_type n)
+{
+ if(n > _capacity)
+ {
+ _capacity = std::max<size_type>(n, 2 * _capacity);
+ _capacity = std::max<size_type>(static_cast<size_type>(240), _capacity);
+ }
+ else if(n < _capacity)
+ {
+ _capacity = n;
}
else
{
- if(n > _capacity)
- {
- _capacity = std::max<size_type>(n, 2 * _capacity);
- _capacity = std::max<size_type>(static_cast<size_type>(240), _capacity);
-
+ return;
+ }
+
#ifdef ICE_SMALL_MESSAGE_BUFFER_OPTIMIZATION
- if(_buf != _fixed)
- {
- _buf = reinterpret_cast<pointer>(realloc(_buf, _capacity));
- }
- else
- {
- _buf = reinterpret_cast<pointer>(malloc(_capacity));
- memcpy(_buf, _fixed, _size);
- }
+ 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));
- }
- else
- {
- _buf = reinterpret_cast<pointer>(malloc(_capacity));
- }
+ if(_buf)
+ {
+ _buf = reinterpret_cast<pointer>(realloc(_buf, _capacity));
+ }
+ else
+ {
+ _buf = reinterpret_cast<pointer>(malloc(_capacity));
+ }
#endif
-
- if(!_buf)
- {
- SyscallException ex(__FILE__, __LINE__);
- ex.error = getSystemErrno();
- throw ex;
- }
- }
-
- _size = n;
+
+ if(!_buf)
+ {
+ SyscallException ex(__FILE__, __LINE__);
+ ex.error = getSystemErrno();
+ throw ex;
}
}
diff --git a/cppe/src/IceE/Connection.cpp b/cppe/src/IceE/Connection.cpp
index 746d906cf94..9c036b1b9a5 100755
--- a/cppe/src/IceE/Connection.cpp
+++ b/cppe/src/IceE/Connection.cpp
@@ -1610,8 +1610,8 @@ Ice::Connection::run()
#ifndef ICEE_PURE_CLIENT
Int invokeNum = 0;
_in.os()->reset();
- _in.is()->reset();
#endif
+ _stream.reset();
//
// Read and parse the next message. We don't need to lock the