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
0
votes
1 answer

Segment fault on memcpy tcp socket

I'm writing a client connecting to a server. I got a Segmentation Fault on line 124 memcpy() of the TCP socket. With the UDP connection I want to obtain the IP address of a server on the network, then, obtained the IP, I want to connect with it…
phcaze
  • 1,707
  • 5
  • 27
  • 58
0
votes
4 answers

Using memcpy to read two integers from a memory block

I am trying to read two integers, stored consecutively, from a memory block (i have a pointer void *block pointing to the contents of the block) using memcpy. The first one is read just fine using: memcpy(&test, block, sizeof(int)); I try to read…
nikos
  • 2,893
  • 11
  • 30
  • 39
0
votes
4 answers

Is memcpy() unsafe in Mac OS X?

I know there is a great deal of discussion about how memcpy() is unsafe in the Windows/Microsoft world, but does that apply to Mac OS X code as well (Cocoa)? If so, what function should be used in Cocoa for maximum safety? memcpy_s() doesn't seem to…
Locksleyu
  • 5,192
  • 8
  • 52
  • 77
-1
votes
5 answers

memcpy() operation on the integer arrays in the constructor gives unexpected output in C++

I know I could use std::vector in C++ instead of arrays and save me some trouble. However this question is not for practical application. Its rather for my understanding. I see '0' instead of the actual value on memcpy() operation. What am I doing…
enthusiasticgeek
  • 2,640
  • 46
  • 53
-1
votes
0 answers

memcpy does not copy the data

I am caught up with a weird problem. I have one build that copies data using memcpy, while another build does not. I don't understand why, because the relevant file is still the same. I am using following code: memcpy(pxCurrentInfo,…
user437777
  • 1,423
  • 4
  • 17
  • 28
-1
votes
7 answers

Assignment vs mempcy - which will be faster in this case

which of the two is faster: ? 1. char* _pos ..; short value = ..; *((short*)_pos = va; 2. char* _pos ..; short value = ..; memcpy(_pos, &value, sizeof(short));
Erik Sapir
  • 23,209
  • 28
  • 81
  • 141
-1
votes
1 answer

Copying an unsigned int array in C

I have to create an unsigned int array to make an IR remote message. To do this, I have to concatenate the header to the data bits, depending of which key I want to mimic. Here's what I have and the problem: #include #include…
Rodrigo Castro
  • 1,573
  • 14
  • 38
-1
votes
1 answer

warning: memcpy forming offset [X, Y] is out of the bounds [0, 2] of object Z

I'm trying to assemble information in a struct to later memcopy it to an spi buffer. This is the code I'm working with: Demo #include #include #include /* memcpy */ using data_settings = uint8_t; enum class…
glades
  • 3,778
  • 1
  • 12
  • 34
-1
votes
1 answer

Changing from assignment operator "=" to memcpy for copying bytes resulting in segmentation fault

I've written code to place a smaller BMP file (A) in a bigger BMP file (B) in Android Native Code. Edit: more details on what fileA and fileB are like //initialised as global variables char * fileA; char * fileB; //file A and B are passed in to…
-1
votes
3 answers

C struct type confusing

struct payload{ struct metadata meta; char data_pointer[0]; }; struct payload* mypayload = (struct payload*) malloc(sizeof(struct payload) + 50); What is the type of mypayload here? The address, pointer, or something else
FrankZZZ
  • 31
  • 2
-1
votes
1 answer

realloc implementation without memcpy

can you please check this code to see why my implementation of a realloc function without using memcpy doesn't work? I am trying to figure out a way to transfer the payload size and tags from one block to another block. I got an invalid pointer…
Killerbee
  • 1
  • 2
-1
votes
1 answer

copy array of "vectors": by memcpy or iterate each?

here's a snippet of code I have: for (int oscIndex = 0; oscIndex < kNumOscs; oscIndex++) { for (int voiceIndex = 0; voiceIndex < numVoices; voiceIndex += 4) { const int v = voiceIndex / 4; // vol osc[oscIndex][v] =…
markzzz
  • 47,390
  • 120
  • 299
  • 507
-1
votes
1 answer

Why does float output 632 at the end? (Y = 1399109632.000000), while double does not change the number Y = 1399109568.000000

Why does float output 632 at the end? (Y = 1399109632.000000), while double does not change the number Y = 1399109568.000000 #include #include #include int main() { float Y = 1399109568; int D; …
-1
votes
1 answer

why std::copy in reverse order

I want to copy a sequence of bytes into integer values, presumably they will whim with the port's UPD #include #include int main() { uint8_t arr[8]; uint32_t arrNew[2]; arr[0] = 0x11; arr[1] = 0x22; arr[2]…
krespo
  • 35
  • 2
-1
votes
3 answers

Truncate the last few elements of an array

I am new to C and C++, please help me in getting the required solution. I have used memcpy to copy the contents of 'array' to 'arr'. But since the size of 'arr' is 10, it appends 0 to the remaining elements. How can I truncate the 'arr' to size…
Beginner
  • 73
  • 3