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 | 810111b543df53f85bfe5722db79870ca00b1a3e (patch) | |
tree | f52c5a0883413321118c3759011d13360cec9620 | |
parent | 08f80cfa824ba728764b5efea358aafee55aafd4 (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
-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); } |