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
15 answers

C memcpy() a function

Is there any method to calculate size of a function? I have a pointer to a function and I have to copy entire function using memcpy. I have to malloc some space and know 3rd parameter of memcpy - size. I know that sizeof(function) doesn't work. Do…
sync
  • 51
  • 1
  • 2
5
votes
1 answer

ZMQ: Sending custom CPP object over the ZMQ queue

I have a class named GenericMessage shown in the 1st code snippet below (defined in GenericMessage.hxx). I have a .cpp file named TestFE.cpp (see the 2nd code snippet below) that attempts to send an instance of class GenericMessage via a ZMQ queue…
F. Aydemir
  • 2,665
  • 5
  • 40
  • 60
5
votes
2 answers

is there a Python Equivalent to Memcpy

I am trying to port some C Code but I am really stuck cause of the use of memcpy I tried with ctypes (did not work). I am hoping to find a python way of using an equivalent function of memcpy Any ideas Here is an example of the C Code I am trying to…
townlong
  • 189
  • 1
  • 7
  • 20
5
votes
5 answers

Will memcpy or memmove cause problems copying classes?

Suppose I have any kind of class or structure. No virtual functions or anything, just some custom constructors, as well as a few pointers that would require cleanup in the destructor. Would there be any adverse affects to using memcpy or memmove on…
Serge
  • 1,974
  • 6
  • 21
  • 33
5
votes
1 answer

Fast ARM NEON memcpy

I want to copy an image on an ARMv7 core. The naive implementation is to call memcpy per line. for(i = 0; i < h; i++) { memcpy(d, s, w); s += sp; d += dp; } I know that the following d, dp, s, sp, w are all 32-byte aligned, so my next (still…
robbie_c
  • 2,428
  • 1
  • 19
  • 28
5
votes
3 answers

How can I use memcpy to copy data from two integers to an array of characters?

I have a file that can store up to 8 bytes of data. I have a system(let's call is Sys1) which can bring me 8 bytes from the file and save it in a buffer inside the ram. I can use these 8 bytes and copy some stuff in it, and then use this system to…
jan1
  • 613
  • 2
  • 10
  • 17
4
votes
2 answers

Time taken for memcpy decreases after certain point

I ve a code which increases the size of the memory(identified by a pointer) exponentially. Instead of realloc(), I use malloc() followed by memcpy()... int size=5,newsize; int *c = malloc(size*sizeof(int)); int *temp; while(1) { …
tss
  • 111
  • 1
  • 6
4
votes
4 answers

C++ Char pointer to char array

None of the posted answers I've read work, so I'm asking again. I'm trying to copy the string data pointed to by a char pointer into a char array. I have a function that reads from a ifstream into a char array char* FileReader::getNextBytes(int…
Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724
4
votes
6 answers

Memcpy : Adding an int offset?

I was looking over some C++ code and I ran into this memcpy function. I understand what memcpy does but they add an int to the source. I tried looking up the source code for memcpy but I can't seem to understand what the adding is actually doing…
user1007682
  • 43
  • 1
  • 1
  • 4
4
votes
2 answers

C: Memcpy vs Shifting: Whats more efficient?

I have a byte array containing 16 & 32bit data samples, and to cast them to Int16 and Int32 I currently just do a memcpy with 2 (or 4) bytes. Because memcpy is probably isn't optimized for lenghts of just two bytes, I was wondering if it would be…
Maestro
  • 9,046
  • 15
  • 83
  • 116
4
votes
1 answer

Profiling memcpy performance on Cortex-M7 (stm32f7)

SHORT VERSION: Performance metrics of the memcpy that gets pulled from the GNU ARM toolchain seem to vary wildly on ARM Cortex-M7 for different copy sizes, even though the code that copies the data always stays the same. What could be the cause of…
Nuwanda
  • 123
  • 1
  • 6
4
votes
1 answer

Device sync during async memcpy in CUDA

Suppose I want to perform an async memcpy host to device in CUDA, then immediately run the kernel. How can I test in the kernel if the async transfer has completed ?
Stefano Borini
  • 138,652
  • 96
  • 297
  • 431
4
votes
3 answers

Concatenate with memcpy

I'm trying to add two strings together using memcpy. The first memcpy does contain the data, I require. The second one does not however add on. Any idea why? if (strlen(g->db_cmd) < MAX_DB_CMDS ) { …
ken
  • 283
  • 2
  • 6
  • 12
4
votes
2 answers

memcpy() performance- Ubuntu x86_64

I am observing some weird behavior which I am not being able to explain. Following are the details :- #include #include #include #include void memcpy_test() { int size = 32*4; char* src = new…
Faraz
  • 131
  • 1
  • 6
4
votes
1 answer

Memcpy data directly into std::vector

Is it legal to directly copy data into a std::vector using memcpy? Something like this: char buf[255]; FillBuff(buf); std::vector vbuf; vbuf.resize(255) memcpy(vbuf.data(), &buf, 255);
Dess
  • 2,064
  • 19
  • 35