summaryrefslogtreecommitdiff
path: root/cpp/zone.cpp
diff options
context:
space:
mode:
authorfrsyuki <frsyuki@5a5092ae-2292-43ba-b2d5-dcab9c1a2731>2009-02-15 09:09:56 +0000
committerfrsyuki <frsyuki@5a5092ae-2292-43ba-b2d5-dcab9c1a2731>2009-02-15 09:09:56 +0000
commit990ac38ccdb51acc520fa43c99115cb216ec95e6 (patch)
tree47e1cac5605c2839fd7ae5af4ae30ed34060e2f3 /cpp/zone.cpp
parent249d3e9c908ea4a3fd2012a753ca7f0cea0b4ee5 (diff)
downloadmsgpack-python-990ac38ccdb51acc520fa43c99115cb216ec95e6.tar.gz
lang/c/msgpack: C++ binding: implemented built-in buffer.
git-svn-id: file:///Users/frsyuki/project/msgpack-git/svn/x@55 5a5092ae-2292-43ba-b2d5-dcab9c1a2731
Diffstat (limited to 'cpp/zone.cpp')
-rw-r--r--cpp/zone.cpp29
1 files changed, 19 insertions, 10 deletions
diff --git a/cpp/zone.cpp b/cpp/zone.cpp
index 5031467..de2de22 100644
--- a/cpp/zone.cpp
+++ b/cpp/zone.cpp
@@ -6,27 +6,36 @@ namespace msgpack {
void* zone::alloc()
{
if(m_used >= m_pool.size()*MSGPACK_ZONE_CHUNK_SIZE) {
- m_pool.push_back(chunk_t());
+ m_pool.push_back(new chunk_t());
}
- void* data = m_pool[m_used/MSGPACK_ZONE_CHUNK_SIZE].cells[m_used%MSGPACK_ZONE_CHUNK_SIZE].data;
+ void* data = m_pool[m_used/MSGPACK_ZONE_CHUNK_SIZE]->cells[m_used%MSGPACK_ZONE_CHUNK_SIZE].data;
++m_used;
return data;
}
void zone::clear()
{
- for(size_t b=0; b < m_used/MSGPACK_ZONE_CHUNK_SIZE; ++b) {
- cell_t* c(m_pool[b].cells);
- for(size_t e=0; e < MSGPACK_ZONE_CHUNK_SIZE; ++e) {
+ if(!m_pool.empty()) {
+ for(size_t b=0; b < m_used/MSGPACK_ZONE_CHUNK_SIZE; ++b) {
+ cell_t* c(m_pool[b]->cells);
+ for(size_t e=0; e < MSGPACK_ZONE_CHUNK_SIZE; ++e) {
+ reinterpret_cast<object_class*>(c[e].data)->~object_class();
+ }
+ }
+ cell_t* c(m_pool.back()->cells);
+ for(size_t e=0; e < m_used%MSGPACK_ZONE_CHUNK_SIZE; ++e) {
reinterpret_cast<object_class*>(c[e].data)->~object_class();
}
- }
- cell_t* c(m_pool.back().cells);
- for(size_t e=0; e < m_used%MSGPACK_ZONE_CHUNK_SIZE; ++e) {
- reinterpret_cast<object_class*>(c[e].data)->~object_class();
+
+ for(pool_t::iterator it(m_pool.begin()), it_end(m_pool.end());
+ it != it_end;
+ ++it) {
+ delete *it;
+ }
+ m_pool.clear();
}
m_used = 0;
- m_pool.resize(1);
+
for(user_finalizer_t::reverse_iterator it(m_user_finalizer.rbegin()), it_end(m_user_finalizer.rend());
it != it_end;
++it) {