Skip to content

Commit

Permalink
employed initialise_with_0 flag to reduce unnecessary 0-fill
Browse files Browse the repository at this point in the history
  • Loading branch information
evgueni-ovtchinnikov committed Dec 9, 2024
1 parent e50e6b1 commit 3b2b84c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/buildblock/ProjDataInMemory.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,18 @@ ProjDataInMemory::ProjDataInMemory(shared_ptr<const ExamInfo> const& exam_info_s
void
ProjDataInMemory::create_buffer(const bool initialise_with_0)
{
if (!initialise_with_0) {
this->buffer.set_initialise_with_zeros(false);
this->buffer.grow(0, this->size_all());
return;
}
#if 0
float *b = new float[this->size_all()];
if (initialise_with_0)
memset(b, 0, this->size_all()*sizeof(float));
return b;
#else
this->buffer.set_initialise_with_zeros(true);
this->buffer = Array<1, float>(static_cast<int>(this->size_all()));
#endif
}
Expand Down
11 changes: 11 additions & 0 deletions src/include/stir/Array.h
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,15 @@ class Array<1, elemT> : public NumericVectorWithOffset<elemT, elemT>
inline const elemT& at(const BasicCoordinate<1, int>& c) const;
//@}

void set_initialise_with_zeros(bool iwz)
{
init_with_zeros_ = iwz;
}
bool get_initialise_with_zeros() const
{
return init_with_zeros_;
}

private:
// Make sure we can call init() recursively.
template <int num_dimensions2, class elemT2>
Expand All @@ -579,6 +588,8 @@ class Array<1, elemT> : public NumericVectorWithOffset<elemT, elemT>
\arg data_ptr should start to a contiguous block of correct size
*/
inline void init(const IndexRange<1>& range, elemT* const data_ptr, bool copy_data);

bool init_with_zeros_= 0;
};

END_NAMESPACE_STIR
Expand Down
6 changes: 6 additions & 0 deletions src/include/stir/Array.inl
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,12 @@ Array<1, elemT>::resize(const int min_index, const int max_index)
const size_type oldlength = this->size();

base_type::resize(min_index, max_index);

if (!get_initialise_with_zeros()) {
this->check_state();
return;
}

if (oldlength == 0)
{
for (int i = this->get_min_index(); i <= this->get_max_index(); i++)
Expand Down

0 comments on commit 3b2b84c

Please sign in to comment.