Bug fixed, never mix destroy_ptr and allocate.

This commit is contained in:
Dongryeol Lee
2010-11-22 03:34:40 +00:00
parent 550af72cf6
commit 2bcf4e4698
7 changed files with 19 additions and 27 deletions
@@ -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<double>(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<double>(
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<double>(
point_in.length()) :
new double[point_in.length()];
CopyValues(point_in);
}
@@ -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();
@@ -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<typename MyType>
void DestroyPtr(MyType *ptr) {
m_file_.destroy_ptr(ptr);
@@ -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();
@@ -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<TreeType>() : new TreeType();
*right = (m_file_in) ?
m_file_in->Construct<TreeType>() : new TreeType();
// Copy the split dimension and split value.
(*left)->bound().Init(matrix.n_rows());
@@ -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();
@@ -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<core::math::Range>(
dimension) :
new core::math::Range[dimension];
dim_ = dimension;