2
0
mirror of https://github.com/boostorg/compute.git synced 2026-01-27 06:42:19 +00:00

Don't auto-initialize values in vector

This changes the vector class to not auto-initialize values
when it is created or resized. This improves performance by
eliminating a call to fill(). If needed, user code can call
fill() explicitly on the newly allocated values.
This commit is contained in:
Kyle Lutz
2013-04-27 10:30:26 -04:00
parent 03195275b3
commit 0ab2fe85eb
2 changed files with 11 additions and 13 deletions

View File

@@ -16,6 +16,16 @@
<purpose>allocator type</purpose>
</template-type-parameter>
</template>
<description>
<para>
Note: Unlike <code>std::vector</code>,
<code>boost::compute::vector</code> does not initialize values
when the created or resized. If initialization is needed you must
explicitly call <functionname>fill()</functionname> on the newly
allocated values.
</para>
</description>
</class>
</namespace>
</namespace>

View File

@@ -30,7 +30,6 @@
#include <boost/compute/context.hpp>
#include <boost/compute/command_queue.hpp>
#include <boost/compute/algorithm/copy.hpp>
#include <boost/compute/algorithm/fill.hpp>
#include <boost/compute/algorithm/fill_n.hpp>
#include <boost/compute/container/allocator.hpp>
#include <boost/compute/iterator/buffer_iterator.hpp>
@@ -242,17 +241,9 @@ public:
return m_allocator.max_size();
}
void resize(size_type size, T value = T())
void resize(size_type size)
{
if(size < capacity()){
if(size < m_size){
::boost::compute::fill(
begin() + static_cast<difference_type>(size),
begin() + static_cast<difference_type>(m_size),
value
);
}
m_size = size;
}
else {
@@ -272,9 +263,6 @@ public:
// copy old values to the new buffer
::boost::compute::copy(m_data, m_data + m_size, new_data, queue);
// fill the rest of the new vector with value
::boost::compute::fill(new_data + m_size, new_data + size, value, queue);
// free old memory
m_allocator.deallocate(m_data, m_size);