Questions tagged [memcpy]

memcpy() is a C standard library function used for copying a block of memory bytes from one place to another.

Synopsis

#include <string.h>

void *memcpy(void * restrict s1,
     const void * restrict s2,
     size_t n);

Description
The memcpy function copies n characters from the object pointed to by s2 into the object pointed to by s1. If copying takes place between objects that overlap, the behavior is undefined.

Returns
The memcpy function returns the value of s1.

1578 questions
5
votes
4 answers

memcpy() safety on adjacent memory regions

I recently asked a question on using volatile and was directed to read some very informative articles from Intel and others discussing memory barriers and their uses. After reading these articles I have become quite paranoid though. I have a…
JaredC
  • 5,150
  • 1
  • 20
  • 45
5
votes
1 answer

Type-Safe C++ wrapper for memcpy?

Given that std::copy (for Trivial Types obviously) can only be implemented as a wrapper around memmove(*), I'm wondering: Is there a Standard C++ type-safe wrapper for the times you need memcpy? (I can't count the number of times I forgot to…
Martin Ba
  • 37,187
  • 33
  • 183
  • 337
5
votes
3 answers

clang vs gcc for copying 3 bytes on x86_64 - number of mov's

What should optimized compiled code for copying 3 bytes from one place to another, say, using memcpy(,,3) look like, in terms of assembly instructions? Consider the following program: #include int main() { int* p = (int*) 0x10; int x…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
5
votes
1 answer

xcode 7.3.1, getting error memcpy no member in namespace

when trying to compile some c / c++ code for iOS. Getting No member named 'memcpy' in namespace 'std::__1'; did you mean 'wmemcpy'? Have tried the compiler settings with no luck. This is in the memory file in the tool chain.
ort11
  • 3,359
  • 4
  • 36
  • 69
5
votes
3 answers

How to copy memory from source thats not on byte alignment (shifted)

I can think of some nasty inefficient ways to accomplish this task, but I'm wondering what the best way is. For example I want to copy 10 bytes starting at the 3rd bit in a byte and copy to a pointer as usual. Is there a better way than to copy one…
Ryu
  • 8,641
  • 10
  • 65
  • 98
5
votes
3 answers

memcpy segmentation fault. Misalignment of data structure boundaries

I am trying to debug this error but have not been able to do it for a while now. I have tried to use memmove as an alternative but that also results in a segmentation fault. The link to the code in this question is posted at -…
Choi
  • 151
  • 1
  • 2
  • 13
5
votes
1 answer

How to handle a python list with PyCUDA?

I guess this is a rather easy question for an expert, yet I can't find any answers in the net. Given a simple case: The problem: listToProcess = [] for i in range(0, 10): listToProcess.append(i) This list shall be transfered to the GPU, for…
user3085931
  • 1,757
  • 4
  • 29
  • 55
5
votes
0 answers

glMapBufferRange() is slow and memcpy() of the mapped data is also slow on Android

I managed to write a video recording demo which is similar to ContinuousCaptureActivity of grafika(Source code of ContinuousCaptureActivity.java). The difference is that grafika used hardware encoding but I used software encoding. For software…
dragonfly
  • 1,151
  • 14
  • 35
5
votes
2 answers

'memcpy'-like function that supports offsets by individual bits?

I was thinking about solving this, but it's looking to be quite a task. If I take this one by myself, I'll likely write it several different ways and pick the best, so I thought I'd ask this question to see if there's a good library that solves this…
VoidStar
  • 5,241
  • 1
  • 31
  • 45
5
votes
4 answers

Deletion Using memcpy in an array

Given an index and an array of integers, I need to delete the element in the given array which was stored in the given index through the use of memcpy(). The new set of elements will be stored on the given array. Here's an illustration of what I…
Kael
  • 391
  • 1
  • 10
  • 21
5
votes
2 answers

Using memcpy and friends with memory-mapped I/O

I'm working on an embedded project which involves I/O on memory-mapped FPGA registers. Pointers to these memory regions need to be marked volatile so the compiler does not "optimize out" reads and writes to the FPGA by caching values in CPU…
Matt Kline
  • 10,149
  • 7
  • 50
  • 87
5
votes
1 answer

can memcpy for std::aligned_storage?

std::aligned_storage::type is POD type. POD type can memcpy. However, What happens if placement new non-trivially-copyable type to std::aligned_storage? Can it memcpy that std::aligned_storage? non-trivially-copyable type(non-POD type) can NOT…
Cocoa
  • 95
  • 4
5
votes
2 answers

Using memcpy to copy an array of objects

Recently I have encountered the error double free or corruption error in my project. After some test runs , the problem is pinned down to the copy function which uses memcpy. class Pen { string make; string model; string color; …
GalaxyVintage
  • 656
  • 1
  • 11
  • 20
5
votes
5 answers

Concatenate two arrays using void pointer (C)

I want to concatenate two arrays of the same type into a single new array with the same type. But the problem is I have to use void pointers, and somehow my code won't work from the third element on. I searched a bit on the internet but seems like…
Kuro95
  • 97
  • 7
5
votes
2 answers

Valid uses cases for reinterpret_cast for unaligned memory access vs memcpy?

In the internals of snappy, there is a conditionally compiled section that selects dereferencing a reinterpret_cast'ed pointer as the best implementation for reads and writes of potentially unaligned 16, 32, and 64 bit integers on architectures that…
acm
  • 12,183
  • 5
  • 39
  • 68