Commit b3792277 authored by Paal Kvamme's avatar Paal Kvamme
Browse files

Remove the just-in-case zeroing of new DataBuffer instances.

parent 5f141b8c
......@@ -462,7 +462,11 @@ DataBufferNd<T,NDim>::DataBufferNd(const std::array<std::int64_t,NDim>& size)
{
SimpleTimer tt(AdHocTimers::instance().ctor, timers_on());
check_stride(_size, _stride);
memset(_data.get(), 0, make_product(size) * sizeof(T));
// TODO-Worry: Leaving the buffer not initialized might turn an easily
// reproducible bug into a heissenbug. But zeroing the buffers here
// is too wasteful. If you must, then do a fill() just after constructing
// a new buffer,
//memset(_data.get(), 0, make_product(size) * sizeof(T));
}
template <typename T, int NDim>
......
......@@ -44,6 +44,7 @@ void test_databuffer_construct()
{
//** Allocate a new buffer and take ownership of it.
DataBufferNd<float,3> buffer(std::array<std::int64_t,3>{64, 50, 100});
buffer.fill(0);
TEST_CHECK(!buffer.isScalar());
TEST_CHECK(buffer.data() != nullptr);
TEST_CHECK(buffer.data() == buffer.voidData().get());
......@@ -111,6 +112,7 @@ void test_databuffer_scale()
{
//** Regular buffer
auto buffer = std::make_shared<intbuffer_t>(size, stride);
buffer->fill(0);
buffer->data()[0] = 0;
buffer->data()[1] = 1;
buffer->data()[2] = 7;
......@@ -178,6 +180,7 @@ void test_databuffer_copyfrom()
// A user has requested reading data from survey's origin and with
// size (100, 90, 110). The buffer is allocated by us.
DataBufferNd<float,3> target(std::array<std::int64_t,3>{100,90,110});
target.fill(0);
std::array<std::int64_t,3> targetorigin{0, 0, 0};
// 64^3 samples worth of -999.25 has been read from (0,0,64) in the survey
......@@ -189,7 +192,7 @@ void test_databuffer_copyfrom()
target.copyFrom(&brick, orig1, targetorigin.data(), nullptr, nullptr);
TEST_CHECK(target.data()[0] == 0); // data[0,0,0] was not touched.
TEST_CHECK(target.data()[64] == -999.25); // dara[0,0,64] should have been.
TEST_CHECK(target.data()[64] == -999.25); // data[0,0,64] should have been.
TEST_CHECK(countequal(-999.25,target.data(),target.totalsize()) == 64*64*46);
// 100 samples implicitly constant 3.5 at survey address (7,9,13).
......@@ -251,6 +254,7 @@ void test_databuffer_slice()
typedef std::array<std::int64_t,3> ndsize_t;
typedef DataBufferNd<std::int16_t,3> buffer_t;
buffer_t buff(ndsize_t{32,64,128});
buff.fill(0);
TEST_CHECK(buff.ownsdata());
TEST_CHECK(buff.is_cstride());
TEST_CHECK(buff.voidData().use_count() == 2);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment