Change memcpy to memmove in example as ranges may overlap.

Update/regenerate docs.

[SVN r61550]
This commit is contained in:
John Maddock
2010-04-25 08:29:57 +00:00
parent cf879100c6
commit 9dd5a79afa
28 changed files with 109 additions and 40 deletions
+37 -2
View File
@@ -52,7 +52,7 @@ I2 copy_imp(I1 first, I1 last, I2 out, const boost::integral_constant<bool, b>&)
template<typename T>
T* copy_imp(const T* first, const T* last, T* out, const boost::true_type&)
{
memcpy(out, first, (last-first)*sizeof(T));
memmove(out, first, (last-first)*sizeof(T));
return out+(last-first);
}
@@ -71,7 +71,18 @@ inline I2 copy(I1 first, I1 last, I2 out)
return detail::copy_imp(first, last, out, boost::has_trivial_assign<value_type>());
}
}; // namespace opt
} // namespace opt
namespace non_opt
{
template<typename I1, typename I2>
inline I2 copy(I1 first, I1 last, I2 out)
{
return opt::detail::copy_imp(first, last, out, boost::false_type());
}
}
//
// define some global data:
@@ -114,6 +125,18 @@ int cpp_main(int argc, char* argv[])
result = t.elapsed();
cout << "opt::copy<const int*, int*>: " << result << endl;
// cache load:
non_opt::copy(ci_array, ci_array + array_size, i_array);
// time non-optimised version:
t.restart();
for(i = 0; i < iter_count; ++i)
{
non_opt::copy(ci_array, ci_array + array_size, i_array);
}
result = t.elapsed();
cout << "non_opt::copy<const int*, int*>: " << result << endl;
// cache load:
std::copy(ci_array, ci_array + array_size, i_array);
@@ -138,6 +161,18 @@ int cpp_main(int argc, char* argv[])
result = t.elapsed();
cout << "opt::copy<const char*, char*>: " << result << endl;
// cache load:
non_opt::copy(cc_array, cc_array + array_size, c_array);
// time optimised version:
t.restart();
for(i = 0; i < iter_count; ++i)
{
non_opt::copy(cc_array, cc_array + array_size, c_array);
}
result = t.elapsed();
cout << "non_opt::copy<const char*, char*>: " << result << endl;
// cache load:
std::copy(cc_array, cc_array + array_size, c_array);
+35 -1
View File
@@ -69,7 +69,17 @@ inline void fill(I first, I last, const T& val)
detail::do_fill(first, last, val, truth_type());
}
}; // namespace opt
} // namespace opt
namespace non_opt{
template <class I, class T>
inline void fill(I first, I last, const T& val)
{
opt::detail::do_fill(first, last, val, boost::false_type());
}
}
//
// define some global data:
@@ -118,6 +128,18 @@ int cpp_main(int argc, char* argv[])
result = t.elapsed();
cout << "opt::fill<char*, char>: " << result << endl;
// cache load:
non_opt::fill(c_array, c_array + array_size, (char)3);
// time optimised version:
t.restart();
for(i = 0; i < iter_count; ++i)
{
non_opt::fill(c_array, c_array + array_size, (char)3);
}
result = t.elapsed();
cout << "non_opt::fill<char*, char>: " << result << endl;
// cache load:
std::fill(c_array, c_array + array_size, (char)3);
@@ -144,6 +166,18 @@ int cpp_main(int argc, char* argv[])
result = t.elapsed();
cout << "opt::fill<int*, int>: " << result << endl;
// cache load:
non_opt::fill(i_array, i_array + array_size, 3);
// timer optimised version:
t.restart();
for(i = 0; i < iter_count; ++i)
{
non_opt::fill(i_array, i_array + array_size, 3);
}
result = t.elapsed();
cout << "non_opt::fill<int*, int>: " << result << endl;
// cache load:
std::fill(i_array, i_array + array_size, 3);