From 2bcf4e46989055b7f418d04644f5b0f8854370e4 Mon Sep 17 00:00:00 2001 From: Dongryeol Lee Date: Mon, 22 Nov 2010 03:34:40 +0000 Subject: [PATCH] Bug fixed, never mix destroy_ptr and allocate. --- .../thesis_research/core/table/dense_point.h | 12 ++++++------ .../thesis_research/core/table/distributed_table.h | 2 +- .../thesis_research/core/table/memory_mapped_file.h | 8 -------- .../dongryel/thesis_research/core/table/table.h | 6 +++--- .../dongryel/thesis_research/core/tree/gen_kdtree.h | 8 ++++---- .../thesis_research/core/tree/general_spacetree.h | 4 ++-- .../dongryel/thesis_research/core/tree/hrect_bound.h | 6 +++--- 7 files changed, 19 insertions(+), 27 deletions(-) diff --git a/fastlib/trunk/contrib/dongryel/thesis_research/core/table/dense_point.h b/fastlib/trunk/contrib/dongryel/thesis_research/core/table/dense_point.h index b904d98797..64da1a5687 100644 --- a/fastlib/trunk/contrib/dongryel/thesis_research/core/table/dense_point.h +++ b/fastlib/trunk/contrib/dongryel/thesis_research/core/table/dense_point.h @@ -34,7 +34,7 @@ class DensePoint { void DestructPtr_() { if(ptr_ != NULL && is_alias_ == false) { if(core::table::global_m_file_) { - core::table::global_m_file_->Deallocate(ptr_.get()); + core::table::global_m_file_->DestroyPtr(ptr_.get()); } else { delete[] ptr_.get(); @@ -109,7 +109,7 @@ class DensePoint { ptr_ = (core::table::global_m_file_) ? (double *) - core::table::global_m_file_->Allocate(sizeof(double) * length_in) : + core::table::global_m_file_->ConstructArray(length_in) : new double[length_in]; n_rows_ = length_in; is_alias_ = false; @@ -119,8 +119,8 @@ class DensePoint { ptr_ = (core::table::global_m_file_) ? (double *) - core::table::global_m_file_->Allocate( - sizeof(double) * vector_in.size()) : + core::table::global_m_file_->ConstructArray( + vector_in.size()) : new double[vector_in.size()]; n_rows_ = vector_in.size(); for(unsigned int i = 0; i < vector_in.size(); i++) { @@ -139,8 +139,8 @@ class DensePoint { void Copy(const DensePoint &point_in) { ptr_ = (core::table::global_m_file_) ? - (double *) core::table::global_m_file_->Allocate( - sizeof(double) * point_in.length()) : + (double *) core::table::global_m_file_->ConstructArray( + point_in.length()) : new double[point_in.length()]; CopyValues(point_in); } diff --git a/fastlib/trunk/contrib/dongryel/thesis_research/core/table/distributed_table.h b/fastlib/trunk/contrib/dongryel/thesis_research/core/table/distributed_table.h index 710cb0a7af..da4b660235 100644 --- a/fastlib/trunk/contrib/dongryel/thesis_research/core/table/distributed_table.h +++ b/fastlib/trunk/contrib/dongryel/thesis_research/core/table/distributed_table.h @@ -168,7 +168,7 @@ class DistributedTable: public boost::noncopyable { // distributed table. if(local_n_entries_ != NULL) { if(core::table::global_m_file_) { - core::table::global_m_file_->Deallocate(local_n_entries_.get()); + core::table::global_m_file_->DestroyPtr(local_n_entries_.get()); } else { delete[] local_n_entries_.get(); diff --git a/fastlib/trunk/contrib/dongryel/thesis_research/core/table/memory_mapped_file.h b/fastlib/trunk/contrib/dongryel/thesis_research/core/table/memory_mapped_file.h index 132f5d7c73..e6505e4c12 100644 --- a/fastlib/trunk/contrib/dongryel/thesis_research/core/table/memory_mapped_file.h +++ b/fastlib/trunk/contrib/dongryel/thesis_research/core/table/memory_mapped_file.h @@ -67,14 +67,6 @@ class MemoryMappedFile { boost::interprocess::anonymous_instance)(); } - void *Allocate(size_t size) { - return m_file_.allocate(size); - } - - void Deallocate(void *p) { - m_file_.deallocate(p); - } - template void DestroyPtr(MyType *ptr) { m_file_.destroy_ptr(ptr); diff --git a/fastlib/trunk/contrib/dongryel/thesis_research/core/table/table.h b/fastlib/trunk/contrib/dongryel/thesis_research/core/table/table.h index e641c6ba84..4ec6aa758c 100644 --- a/fastlib/trunk/contrib/dongryel/thesis_research/core/table/table.h +++ b/fastlib/trunk/contrib/dongryel/thesis_research/core/table/table.h @@ -158,7 +158,7 @@ class Table: public boost::noncopyable { ~Table() { if(tree_.get() != NULL) { if(core::table::global_m_file_) { - core::table::global_m_file_->Deallocate(tree_.get()); + core::table::global_m_file_->DestroyPtr(tree_.get()); } else { delete tree_.get(); @@ -167,7 +167,7 @@ class Table: public boost::noncopyable { } if(old_from_new_.get() != NULL) { if(core::table::global_m_file_) { - core::table::global_m_file_->Deallocate(old_from_new_.get()); + core::table::global_m_file_->DestroyPtr(old_from_new_.get()); } else { delete[] old_from_new_.get(); @@ -176,7 +176,7 @@ class Table: public boost::noncopyable { } if(new_from_old_.get() != NULL) { if(core::table::global_m_file_) { - core::table::global_m_file_->Deallocate(new_from_old_.get()); + core::table::global_m_file_->DestroyPtr(new_from_old_.get()); } else { delete[] new_from_old_.get(); diff --git a/fastlib/trunk/contrib/dongryel/thesis_research/core/tree/gen_kdtree.h b/fastlib/trunk/contrib/dongryel/thesis_research/core/tree/gen_kdtree.h index f96d76e776..213dcd4d93 100644 --- a/fastlib/trunk/contrib/dongryel/thesis_research/core/tree/gen_kdtree.h +++ b/fastlib/trunk/contrib/dongryel/thesis_research/core/tree/gen_kdtree.h @@ -126,10 +126,10 @@ class GenKdTree { return false; } else { - *left = (m_file_in) ? (TreeType *) - m_file_in->Allocate(sizeof(TreeType)) : new TreeType(); - *right = (m_file_in) ? (TreeType *) - m_file_in->Allocate(sizeof(TreeType)) : new TreeType(); + *left = (m_file_in) ? + m_file_in->Construct() : new TreeType(); + *right = (m_file_in) ? + m_file_in->Construct() : new TreeType(); // Copy the split dimension and split value. (*left)->bound().Init(matrix.n_rows()); diff --git a/fastlib/trunk/contrib/dongryel/thesis_research/core/tree/general_spacetree.h b/fastlib/trunk/contrib/dongryel/thesis_research/core/tree/general_spacetree.h index 8b2ef4c115..723a331812 100644 --- a/fastlib/trunk/contrib/dongryel/thesis_research/core/tree/general_spacetree.h +++ b/fastlib/trunk/contrib/dongryel/thesis_research/core/tree/general_spacetree.h @@ -97,7 +97,7 @@ class GeneralBinarySpaceTree { ~GeneralBinarySpaceTree() { if(left_.get() != NULL) { if(core::table::global_m_file_) { - core::table::global_m_file_->Deallocate(left_.get()); + core::table::global_m_file_->DestroyPtr(left_.get()); } else { delete left_.get(); @@ -106,7 +106,7 @@ class GeneralBinarySpaceTree { } if(right_.get() != NULL) { if(core::table::global_m_file_) { - core::table::global_m_file_->Deallocate(right_.get()); + core::table::global_m_file_->DestroyPtr(right_.get()); } else { delete right_.get(); diff --git a/fastlib/trunk/contrib/dongryel/thesis_research/core/tree/hrect_bound.h b/fastlib/trunk/contrib/dongryel/thesis_research/core/tree/hrect_bound.h index ee67bb5979..48dd5c7d8a 100644 --- a/fastlib/trunk/contrib/dongryel/thesis_research/core/tree/hrect_bound.h +++ b/fastlib/trunk/contrib/dongryel/thesis_research/core/tree/hrect_bound.h @@ -33,7 +33,7 @@ class HrectBound { ~HrectBound() { if(core::table::global_m_file_) { - core::table::global_m_file_->Deallocate(bounds_); + core::table::global_m_file_->DestroyPtr(bounds_); } else { delete[] bounds_; @@ -46,8 +46,8 @@ class HrectBound { */ void Init(int dimension) { bounds_ = (core::table::global_m_file_) ? - (core::math::Range *) core::table::global_m_file_->Allocate( - dimension * sizeof(core::math::Range)) : + core::table::global_m_file_->ConstructArray( + dimension) : new core::math::Range[dimension]; dim_ = dimension;