vecmem 1.18.0
Loading...
Searching...
No Matches
memmove.ipp
1/* VecMem project, part of the ACTS project (R&D line)
2 *
3 * (c) 2025 CERN for the benefit of the ACTS project
4 *
5 * Mozilla Public License Version 2.0
6 */
7#pragma once
8
9namespace vecmem {
10namespace details {
11
12VECMEM_HOST_AND_DEVICE
13inline void memmove(void* dest, const void* src, std::size_t bytes) {
14
15 // Check for some trivial cases.
16 if ((dest == src) || (bytes == 0)) {
17 return;
18 }
19
20 // Cast the char pointers.
21 char* dest_char = static_cast<char*>(dest);
22 const char* src_char = static_cast<const char*>(src);
23
24 if ((dest_char < src_char) || (dest_char >= (src_char + bytes))) {
25 // Non-overlapping, or overlapping such that a forward copy does the
26 // correct thing.
27 for (std::size_t i = 0; i < bytes; ++i) {
29 }
30 } else {
31 // Overlapping such that a backward copy would do the correct thing.
32 for (std::size_t i = bytes; i > 0; --i) {
33 dest_char[i - 1] = src_char[i - 1];
34 }
35 }
36}
37
38} // namespace details
39} // namespace vecmem
An allocator class that wraps a memory resource.
Definition allocator.hpp:37
VECMEM_HOST_AND_DEVICE void memmove(void *dest, const void *src, std::size_t bytes)
Hand-written implementation of a memmove function.
Definition memmove.ipp:13
Main namespace for the vecmem classes/functions.
Definition atomic_ref.hpp:16