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

memcpy for specific byteorder c/c++

1) I have a big buffer 2) I have a lot of variables of almost every types, I use this buffer to send to multiple destinations, with different byte orders. when I send to a network byte order, I usually used htons, or htonl and a customized function…
aah134
  • 860
  • 12
  • 25
0
votes
1 answer

Win32 C++ - Memcpy Function - Access violation error

I am making a self-extracting program, which essentially gets a pointer to the data being extracted (hardcoded) and adds it to a buffer, from which I shall perform operations upon, However, I have encountered a problem, I seem to be getting a…
James
  • 236
  • 5
  • 18
0
votes
3 answers

Some C functions in iOS duplicated as #define

C functions like memcpy and memset are available as C functions as well as #define in iOS: For example the #define memcpy, under the hood, is: #define memcpy(dest, src, len) \ ((__darwin_obsz0 (dest) != (size_t) -1) \ ?…
Khaled Barazi
  • 8,681
  • 6
  • 42
  • 62
0
votes
5 answers

strcpy() of a small string into a bigger string leaves the rest of the bigger string unchanged.How to deal with it?

Here in this sample program to illustrate this behavior of strcpy(),I wrote a string "S" into a bigger string previous which original had "Delaware".But this overwriting only affects the first two characters in the original string.The rest of the…
Rüppell's Vulture
  • 3,583
  • 7
  • 35
  • 49
0
votes
4 answers

C++ Using memcpy to fill a vector in a struct

I would like to fill a struct using memcpy. The struct is declared like this: struct udtFeatures { vectorByteFeatures; }; And this is where I would like fill the bytes: void clsMapping::FeedFeaturesFromMap(udtFeatures…
tmighty
  • 10,734
  • 21
  • 104
  • 218
0
votes
0 answers

On memcpy application crashes - FFMPEG, C++

I have been working with ffmpeg, I got it working good, but I got a memory leak, I followed some instructions to fix it (like use av_frame_unref), so I needed to update ffmpeg to the version 1.2. This is weird for me, because everything was working…
Spamdark
  • 1,341
  • 2
  • 19
  • 38
0
votes
2 answers

Memcpy string as void pointer, incorrect read

I'm trying to create a function that puts together a buffer from arbitrary types. Think basic RPC. So the buffer looks something like { char opcode, uint32_t param1_size, param1, ... , uint32_t paramN_size, paramN } It seems to be working but when…
Pete Jodo
  • 465
  • 1
  • 7
  • 19
0
votes
1 answer

C memcpy Not Behaving as Expected

This question is tied to Making an Array to Hold Arrays of Character Arrays in C Borrowing code from there, I have something that looks like this (credit to luser droog for the nice example code): enum { BUFSZ = 50 }; enum { STRVSZ = 40 }; enum {…
Dae314
  • 385
  • 1
  • 2
  • 9
0
votes
1 answer

Fast memcpy in C#

I want to write a C# method with prototype like this: void memcpy(byte[] dst, int dstOffset, byte[] src, int srcOffset, int len); I have 2 options for this method: 1. void memcpy(byte[] dst, int dstOffset, byte[] src, int srcOffset, int len) { …
Nghia Bui
  • 3,694
  • 14
  • 21
0
votes
7 answers

Why is memcpy() faster?

I'm curious why the memcpy() function is faster than the simple manual copy. Here is my code: #include #include #include #include int main() { clock_t begin, end; double time_spent; int i, j; …
Johnny Mnemonic
  • 3,822
  • 5
  • 21
  • 33
0
votes
2 answers

segmentation fault on memcpy

the full code is in http://docs.google.com/file/d/0B09y_TWqTtwlaHNjdjYybHVIcjA/edit?usp=sharing char data[]="just for a try"; u_char *packet=(u_char *)malloc(28+sizeof(data)); ... ... u_char *udp_data=(u_char…
user138126
  • 953
  • 3
  • 14
  • 29
0
votes
3 answers

adding text in memory allocated

i have created certain amount of memory char* str; str = char(char*) malloc(15); when i do this memcpy(str, "AB", 2); memcpy(str, "CDEFG", 5) cout<<"Value of str: "<
cybercop
  • 105
  • 1
  • 7
0
votes
2 answers

segmentation fault during memcpy

I am trying to make a function which reverses the order of a portion of a string. I'm new to using pointers and for some reason I can access the location of the characters of my string to copy out a substring, but I can't put them back into the same…
ThomDall
  • 11
  • 1
  • 1
0
votes
2 answers

EXC_BAD ACCESS in memcpy

I trying to build a BST and insert nodes in it. However while creating a new node I keep getting exc_bad access error.What can be the reason? Here is my code: struct Node *node_create(struct BSTree *bst,void *nodeKey, struct Value *nodeVal, struct …
user1244069
  • 95
  • 2
  • 12
0
votes
2 answers

wrong memcpy starting from index 1

I am getting wrong memcpy log . i want to take *q (pointer on array in size inNumberOfFrames) . i want to copy it each time to a new array buffersRing[ringNum][inNumberOfFrames] . when in buffersRing[ringNum][0] i save q's size- inNumberOfFrames ,…
user1994291