diff options
author | graehl@gmail.com <graehl@gmail.com@ec762483-ff6d-05da-a07a-a48fb63a330f> | 2010-09-29 04:54:32 +0000 |
---|---|---|
committer | graehl@gmail.com <graehl@gmail.com@ec762483-ff6d-05da-a07a-a48fb63a330f> | 2010-09-29 04:54:32 +0000 |
commit | d2963a1e9311da807c7564274738e6289d8066bf (patch) | |
tree | 6dec8be808da0bcb6b2c0c13367b11898f292fa8 /utils | |
parent | 2516b2cc79720e3d7c7957c42af399e1f100f16a (diff) |
value_array never call allocate(0) since it seems to leak
git-svn-id: https://ws10smt.googlecode.com/svn/trunk@662 ec762483-ff6d-05da-a07a-a48fb63a330f
Diffstat (limited to 'utils')
-rwxr-xr-x | utils/value_array.h | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/utils/value_array.h b/utils/value_array.h index 2010fefe..bd6ef27a 100755 --- a/utils/value_array.h +++ b/utils/value_array.h @@ -171,16 +171,19 @@ public: //copy any existing data like std::vector. not A::construct exception safe. try blah blah? swap? void resize(size_type s, const_reference t = T()) { - pointer na=A::allocate(s); - size_type nc=s<sz ? s : sz; - size_type i=0; - for (;i<nc;++i) - A::construct(na+i,array[i]); - for (;i<s;++i) - A::construct(na+i,t); - clear(); - array=na; - sz=s; + if (s) { + pointer na=A::allocate(s); + size_type nc=s<sz ? s : sz; + size_type i=0; + for (;i<nc;++i) + A::construct(na+i,array[i]); + for (;i<s;++i) + A::construct(na+i,t); + clear(); + array=na; + sz=s; + } else + clear(); } template <class I> @@ -270,7 +273,7 @@ public: ValueArray(ValueArray const& other) : A(other) , sz(other.sz) - , array(A::allocate(sz)) + , array(sz?A::allocate(sz):0) { copy_construct(other.begin(),other.end(),array); @@ -286,7 +289,7 @@ public: ValueArray( Range const& v , typename boost::disable_if< boost::is_integral<Range> >::type* = 0) : sz(boost::size(v)) - , array(A::allocate(sz)) + , array(sz?A::allocate(sz):0) { copy_construct(boost::begin(v),boost::end(v),array); } |