From 0ab2fe85eb6e0cc79c4e5c260fc92d296cc2bd50 Mon Sep 17 00:00:00 2001 From: Kyle Lutz Date: Sat, 27 Apr 2013 10:30:26 -0400 Subject: [PATCH] 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. --- doc/reference/container/vector.xml | 10 ++++++++++ include/boost/compute/container/vector.hpp | 14 +------------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/doc/reference/container/vector.xml b/doc/reference/container/vector.xml index 9c1f2c54..75ed9290 100644 --- a/doc/reference/container/vector.xml +++ b/doc/reference/container/vector.xml @@ -16,6 +16,16 @@ allocator type + + + + Note: Unlike std::vector, + boost::compute::vector does not initialize values + when the created or resized. If initialization is needed you must + explicitly call fill() on the newly + allocated values. + + diff --git a/include/boost/compute/container/vector.hpp b/include/boost/compute/container/vector.hpp index 53bcc8a2..baddb342 100644 --- a/include/boost/compute/container/vector.hpp +++ b/include/boost/compute/container/vector.hpp @@ -30,7 +30,6 @@ #include #include #include -#include #include #include #include @@ -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(size), - begin() + static_cast(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);