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
4
votes
2 answers

What are the changes, if any, to the memcpy lifetime initalization rules in the new standard?

As far as I am aware, memcpy into uninitialized storage cannot safely be used to create an copy of the source object. However, in this thread from last year on the open-std WG21 "ub" list, a participant refers to the new memcpy lifetime-initiation…
BeeOnRope
  • 60,350
  • 16
  • 207
  • 386
4
votes
1 answer

Fast copy every second byte to new memory area

I need a fast way to copy every second byte to a new malloc'd memory area. I have a raw image with RGB data and 16 bits per channel (48 bit) and want to create an RGB image with 8 bits per channel (24 bit). Is there a faster method than copying…
akw
  • 2,090
  • 1
  • 15
  • 21
4
votes
1 answer

GPU ->CPU Memcpy failed in tensorflow word2vec in gpu occured

I I am studying word2vec of tensorflow. We bought two 1080i for parallel processing of gpu. Mounting was successful and p2p was successful. However, I tried to assign it to gpu using the command with tf.device ('/ gpu: 0') The following error occurs…
홍지훈
  • 41
  • 1
  • 2
4
votes
3 answers

Meaning of overlapping when using memcpy

I am trying to understand the function memcpy() which is defined in the C library Syntax: void *memcpy(void*dst,const void*src,size_t n); I know this function is used to copy the contents of the memory pointed by pointer src to the…
user4722851
4
votes
1 answer

Does memcpy preserve data between different types?

Does calling memcpy on two different structures preserve the original data if the buffer size is sufficient? And is it defined to retrieve values of another data type with data of previous data type if their respective data types overlap? This…
user964843
4
votes
1 answer

Odd memcpy_s behaviour in VS2015

recently I was profiling one application, and I have noticed that memcpy_s assembly implementation behaves strangely. I'm talking about implementation residing in Microsoft Visual Studio 14.0\VC\crt\src\i386\memcpy.asm I'm reaching the…
kreuzerkrieg
  • 3,009
  • 3
  • 28
  • 59
4
votes
3 answers

How does memcpy works with void pointers?

I am trying to memcpy from one ptr to another. I know the size that I want to copy. Both the destination and source pointers are void pointers. Is this valid? Does it actually copy the ELEMENT_SIZE (integer like 128) from source to the destination?…
277roshan
  • 354
  • 1
  • 3
  • 13
4
votes
2 answers

Is a memcpy between differently aligned pointers UB?

As far as I understand, the following piece of code exhibits undefined behaviour in C11: #include struct aaaa { char bbbb; int cccc; }; int main(void) { unsigned char buffer[sizeof(struct aaaa)] = { 0 }; struct aaaa *pointer =…
user824425
4
votes
1 answer

Vectorized memcpy that beats _intel_fast_memcpy?

I have implemented a SSE4.2 version of memcpy, but I cannot seem to beat _intel_fast_memcpy on Xeon V3. I use my routine in a gather routine in which the data varies between 4 to 15 bytes at each location. I've looked at many posts here and on…
nineties
  • 423
  • 1
  • 7
  • 17
4
votes
3 answers

Compiler errors calling sprintf: "expected 'char *' but argument is of type 'char'"

I am trying to program a microchip in C. Right now my I'm working to update a line on an LCD screen but it doesnt work correctly. Can anyone shed some light on this? float slope = 0.0626; char *mystring; int8_t LCDline1[20]; void myfunction(){ …
Bob
  • 159
  • 1
  • 1
  • 6
4
votes
1 answer

Type-agnostic memcpy in c99

Related to, but somewhat different from, Do any compilers transfer effective type through memcpy/memmove In C89, memcpy and memmove are required to behave as though the source and destination are accessed using character types, copying all the bits…
supercat
  • 77,689
  • 9
  • 166
  • 211
4
votes
2 answers

Aligning both source and destination address in memcpy

I want to write a memcpy code which does word by word copy instead of byte by byte to increase speed. (Though I need to do some byte by byte copy for the last or few bytes). So I want my source and destination address to be aligned properly. I saw…
Praveen
  • 366
  • 3
  • 12
4
votes
2 answers

ARM/neon memcpy optimized for *uncached* memory?

I'm using a Xilinx Zynq 7000 ARM-based SoC. I'm struggling with DMA buffers (Need help mapping pre-reserved **cacheable** DMA buffer on Xilinx/ARM SoC (Zynq 7000)), so one thing I pursued was faster memcpy. I've been looking at writing a faster…
Timothy Miller
  • 1,527
  • 4
  • 28
  • 48
4
votes
1 answer

unaligned access with memcpy

I'm using a netif struct (similar to http://www.nongnu.org/lwip/structnetif.html) and I got a question related to the alignment. I noticed that every int start on an address that is a multiplier of 4 (e.g. 0x20010db0). However, let's take a look at…
David Lefaivre
  • 191
  • 3
  • 14
4
votes
3 answers

memcpy segfault with larger arrays

I have a function that swaps 2d arrays in C by using memcpy. I know you can swap pointers but I'd like to do a comparison between copying the arrays and swapping pointers. Here is my code for it, the 2d arrays are n x n. void swap_arrays(int n,…
user5004049
  • 691
  • 1
  • 8
  • 17