allocation warning + forwarding + remove unsave code regarding that (e.g. anonymousMove)
This commit is contained in:
parent
2247336fee
commit
bebc7ce35c
6 changed files with 23 additions and 14 deletions
|
@ -9,6 +9,9 @@
|
|||
#include <cassert>
|
||||
#include <iostream>
|
||||
|
||||
#define MIB_SIZE 1024*1024 // 1MiB
|
||||
#define WARN_SIZE MIB_SIZE*100 // 100 MiB
|
||||
|
||||
namespace MultiArrayHelper
|
||||
{
|
||||
|
||||
|
@ -32,6 +35,9 @@ namespace MultiArrayHelper
|
|||
T* allocate(size_t n)
|
||||
{
|
||||
const size_t nn = n*type_size;
|
||||
if(nn >= WARN_SIZE){
|
||||
std::cout << __func__ << ": WARNING: allocating " << nn/(MIB_SIZE) << " MiB" << std::endl;
|
||||
}
|
||||
const size_t off = nn%N;
|
||||
const size_t nnx = (off == 0) ? nn : nn + N - off;
|
||||
const size_t nnd = nnx/N;
|
||||
|
|
|
@ -24,7 +24,7 @@ namespace MultiArrayTools
|
|||
|
||||
template <typename T, class... SRanges>
|
||||
MultiArray<T,SRanges...>::MultiArray(const typename CRange::Space& space,
|
||||
vector<T>&& vec) :
|
||||
const vector<T>& vec) :
|
||||
MutableMultiArrayBase<T,SRanges...>(space),
|
||||
mCont(vec)
|
||||
{
|
||||
|
@ -65,7 +65,7 @@ namespace MultiArrayTools
|
|||
template <typename T, class... SRanges>
|
||||
MultiArray<T,SRanges...>::MultiArray(const std::shared_ptr<SRanges>&... ranges, vector<T>&& vec) :
|
||||
MutableMultiArrayBase<T,SRanges...>(ranges...),
|
||||
mCont(vec)
|
||||
mCont(std::forward<vector<T>>(vec))
|
||||
{
|
||||
MAB::mInit = true;
|
||||
if(mCont.size() > MAB::mRange->size()){
|
||||
|
@ -82,6 +82,7 @@ namespace MultiArrayTools
|
|||
// maybe some checks here in the future...
|
||||
assert(mCont.size() == MAB::mRange->size());
|
||||
MAB::mInit = true;
|
||||
in.mInit = false;
|
||||
}
|
||||
|
||||
template <typename T, class... SRanges>
|
||||
|
@ -91,6 +92,7 @@ namespace MultiArrayTools
|
|||
mCont( std::move( ama.mCont ) )
|
||||
{
|
||||
MAB::mInit = true;
|
||||
ama.mInit = false;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -163,16 +165,16 @@ namespace MultiArrayTools
|
|||
template <class... SRanges2>
|
||||
MultiArray<T,SRanges2...> MultiArray<T,SRanges...>::format(const std::shared_ptr<SRanges2>&... nrs)
|
||||
{
|
||||
MAB::mInit = false;
|
||||
return MultiArray<T,SRanges2...>( nrs... , std::move(mCont) );
|
||||
//MAB::mInit = false;
|
||||
return MultiArray<T,SRanges2...>( nrs... , mCont );
|
||||
}
|
||||
|
||||
template <typename T, class... SRanges>
|
||||
template <class... SRanges2>
|
||||
MultiArray<T,SRanges2...> MultiArray<T,SRanges...>::format(const std::tuple<std::shared_ptr<SRanges2>...>& nrs)
|
||||
{
|
||||
MAB::mInit = false;
|
||||
return MultiArray<T,SRanges2...>( nrs , std::move(mCont) );
|
||||
//MAB::mInit = false;
|
||||
return MultiArray<T,SRanges2...>( nrs , mCont );
|
||||
}
|
||||
|
||||
template <typename T, class... SRanges>
|
||||
|
@ -215,8 +217,9 @@ namespace MultiArrayTools
|
|||
( std::dynamic_pointer_cast<AnonymousRange>( arf.create() ),
|
||||
mCont );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
template <typename T, class... SRanges>
|
||||
std::shared_ptr<MultiArrayBase<T,AnonymousRange> > MultiArray<T,SRanges...>::anonymousMove()
|
||||
{
|
||||
|
@ -226,7 +229,7 @@ namespace MultiArrayTools
|
|||
( std::dynamic_pointer_cast<AnonymousRange>( arf.create() ),
|
||||
std::move(mCont) );
|
||||
}
|
||||
|
||||
*/
|
||||
template <typename T, class... SRanges>
|
||||
MultiArray<T,SRanges...>& MultiArray<T,SRanges...>::operator=(const T& in)
|
||||
{
|
||||
|
|
|
@ -47,7 +47,7 @@ namespace MultiArrayTools
|
|||
MultiArray(const std::shared_ptr<SRanges>&... ranges, MultiArray<T,Ranges...>&& in); // same effect as format
|
||||
|
||||
MultiArray(const typename CRange::Space& space);
|
||||
MultiArray(const typename CRange::Space& space, vector<T>&& vec);
|
||||
MultiArray(const typename CRange::Space& space, const vector<T>& vec);
|
||||
MultiArray(MultiArray<T,AnonymousRange>&& ama, SIZET<SRanges>... sizes);
|
||||
|
||||
// Only if ALL ranges have default extensions:
|
||||
|
@ -90,7 +90,7 @@ namespace MultiArrayTools
|
|||
vector<T>&& vmove() { MAB::mInit = false; return std::move(mCont); }
|
||||
|
||||
virtual std::shared_ptr<MultiArrayBase<T,AnonymousRange> > anonymous(bool slice = false) const override;
|
||||
virtual std::shared_ptr<MultiArrayBase<T,AnonymousRange> > anonymousMove() override;
|
||||
//virtual std::shared_ptr<MultiArrayBase<T,AnonymousRange> > anonymousMove() override;
|
||||
|
||||
auto cat() const
|
||||
-> decltype(ArrayCatter<T>::cat(*this));
|
||||
|
|
|
@ -153,7 +153,7 @@ namespace MultiArrayTools
|
|||
|
||||
virtual bool isConst() const override;
|
||||
|
||||
virtual std::shared_ptr<MultiArrayBase<T,AnonymousRange> > anonymousMove() = 0;
|
||||
//virtual std::shared_ptr<MultiArrayBase<T,AnonymousRange> > anonymousMove() = 0;
|
||||
|
||||
virtual ConstOperationRoot<T,SRanges...>
|
||||
op(const std::shared_ptr<IndexType>& ind) const override;
|
||||
|
|
|
@ -213,14 +213,14 @@ namespace MultiArrayTools
|
|||
assert(0); // think about carefully!!!!
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/*
|
||||
template <typename T, class... SRanges>
|
||||
std::shared_ptr<MultiArrayBase<T,AnonymousRange> > Slice<T,SRanges...>::anonymousMove()
|
||||
{
|
||||
assert(0); // think about carefully!!!!
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
*/
|
||||
template <typename T, class... SRanges>
|
||||
auto Slice<T,SRanges...>::define(const std::shared_ptr<typename SRanges::IndexType>&... inds)
|
||||
-> SliceDef<T,SRanges...>
|
||||
|
|
|
@ -86,7 +86,7 @@ namespace MultiArrayTools
|
|||
virtual auto end() const -> IType override;
|
||||
|
||||
virtual std::shared_ptr<MultiArrayBase<T,AnonymousRange> > anonymous(bool slice = false) const override;
|
||||
virtual std::shared_ptr<MultiArrayBase<T,AnonymousRange> > anonymousMove() override;
|
||||
//virtual std::shared_ptr<MultiArrayBase<T,AnonymousRange> > anonymousMove() override;
|
||||
|
||||
auto define(const std::shared_ptr<typename SRanges::IndexType>&... inds)
|
||||
-> SliceDef<T,SRanges...>;
|
||||
|
|
Loading…
Reference in a new issue