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

Free memory after std::swap and memcpy

I have the following code: Data* t = (Data*)(malloc(len_part_ * sizeof(Data))); memcpy(t, data_[i], len_temp_ * sizeof(Data)); std::swap(t, data_[i]); free(t); The problem is that "A heap has been corrupted" error occruing…
VP.
  • 15,509
  • 17
  • 91
  • 161
-1
votes
1 answer

difference between strncat and memcpy

Please find below code snippet. Is there any chance wherein strncat and memcpy will have different values in pDBVal. If so, Please explain. memcpy(pDBVal, pHash, 20); strncat(pDBVal, cBinSalt, 16); memcpy(pDBVal+20,cBinSalt,16); Ideally…
-1
votes
3 answers

memset is not working properly

I have the following set of code not able to find why I am getting garbage value.My intention is to copy the number of byte as destination irrespective of source to make a generic copy for my application. But not getting the correct result.Is there…
pradipta
  • 1,718
  • 2
  • 13
  • 24
-1
votes
2 answers

memcpy only copies first half of wchar_t array

I am encountering an error when I try to use memcpy on a wchar_t string. Specifically, despite the length I am sending in to memcpy being correct for the length of the string I want to copy, only the first half of the characters in the string are…
CodeRedd
  • 283
  • 1
  • 4
  • 14
-1
votes
2 answers

memcpy() function usage in C

I have a query about using the memcpy() function.I have written the below program, it compiles but doesn't print an output. The .exe opens and the crashes. I am using Code Blocks as my IDE using GNU GCC compiler. int main() { char a[]= "This is…
Kashif Nawaz
  • 95
  • 1
  • 1
  • 13
-1
votes
3 answers

Doing memcpy without allocating memory with malloc before

I am asking myself why this piece of code works well when I haven't allocated memory for fptr. I would expect that it has rather an Undefined Behavior because of doing memcpy without allocating memory for fptr or? struct conf *pconf = NULL; void…
user3329849
  • 9
  • 1
  • 2
-1
votes
2 answers

realloc cause incorrect checksum for freed object

this is a part of my socket client , receive buffer is small than server's send buffer, so I need to realloc buffer, but it throw error like this: malloc: *** error for object 0x7fd44ad00018: incorrect checksum for freed object - object was probably…
NikSun
  • 45
  • 4
-1
votes
3 answers

Safe use of memcpy on overlapping region

Is it safe to use memcpy in the following scenario, where one is copying data from larger index into a block to smaller index in the same block. For example: char buf[100]; // fill in the data ... memcpy(&buf[10], &buf[15], 10); In the above…
-1
votes
1 answer

cudaMemcpyToSymbol use details

I am trying to move data structures from host to constant memory on a Tesla C1060 (compute 1.3). With the following function: //mem.cu #include "kernel.cuh" int InitDCMem(SimuationStruct *sim) { SimParamGPU h_simparam; h_simparam.na =…
mrei
  • 121
  • 14
-1
votes
2 answers

realloc: invalid next size; memcpy

I have code like this: char buf[128]; char *data = NULL; char *temp = NULL; int full = 0; int n = 0; do { bzero(buf, sizeof(buf)); n = recv(newsock, buf, sizeof(buf), 0); full += sizeof(buf); if(n != 0) temp =…
amidnikmal
  • 86
  • 3
  • 9
-1
votes
2 answers

Program crashing on a function prototype declaration

I try to practice generic functions writing this function: void *scramble(void *arr, int ElemSize, int n, int *indArr); But whenever I run the program with a debugger it crashes on the prototype line, using F11 (Step Into) I see the…
Quaker
  • 1,483
  • 3
  • 20
  • 36
-1
votes
2 answers

C++: Reading data from a memory mapped file

I have used MapVirtualFile to map a file under Window using C++ VS2010. The void is void* m_pVoiceData; I would now like to fill a structure with the data. I have been using void clsMapping::FeedPitchmarksFromMap(udtPitchmarks…
tmighty
  • 10,734
  • 21
  • 104
  • 218
-1
votes
1 answer

Overwriting a Static Const Variable

I have written a small method that is supposed to allow me to easily overwrite the value of a static constant variable. Here is the variable I want to change: static const unsigned int myInt; Here is the method that I am trying to…
CgRobot
  • 3
  • 3
-1
votes
2 answers

C array = array faster than memcpy()

I have a piece of C code which I am trying to optimise which involves setting an array a to b. I am currently using memcpy to achieve this, and it works, however it's not fast enough. I.e. double a[4] = {1.0, 2.0, 3.0, 4.0}; double b[4]; memcpy(b,…
-1
votes
1 answer

Please look into this inexplicable behavior and output of memcpy() for overlapping memory blocks

After reading the following about memcpy(), I proceeded to read about memmove(): To avoid overflows, the size of the arrays pointed by both the destination and source parameters, shall be at least num bytes, and should not overlap (for overlapping…
Rüppell's Vulture
  • 3,583
  • 7
  • 35
  • 49
1 2 3
99
100