memcpy

Primitive data type in C to represent the WORD size of a CPU-arch

I observed that size of long is always equal to the WORD size of any given CPU architecture. Is it true for all architectures? I am looking for a portable way to represent a WORD sized variable in C. ...

MemSet & MemCopy

I'm writing a memory allocator, and I need a way to store an integer inside of a chunk of memory. This integer will represent the size of the block so I can navigate to the end given the pointer to the beginning. Here's my test example: // EDIT: Declared space for testInt int* testInt = new int; head_ptr = (char*) malloc(4*1024*1...

Using memcpy to copy managed structures

Hi, I am working in mixed mode (managed C++ and C++ in one assembly). I am in a situation something like this. ManagedStructure ^ managedStructure = gcnew ManagedStructure(); //here i set different properties of managedStructure then I call "Method" given below and pass it "& managedStructure" Method(void *ptrToStruct) { Manag...

memcpy segmentation fault on linux but not os x

I'm working on implementing a log based file system for a file as a class project. I have a good amount of it working on my 64 bit OS X laptop, but when I try to run the code on the CS department's 32 bit linux machines, I get a seg fault. The API we're given allows writing DISK_SECTOR_SIZE (512) bytes at a time. Our log record consists...

memcpy(), what should the value of the size parameter be?

Hi, I want to copy an int array to another int array. They use the same define for length so they'll always be of the same length. What are the pros/cons of the following two alternatives of the size parameter to memcpy()? memcpy(dst, src, ARRAY_LENGTH*sizeof(int)); or memcpy(dst, src, sizeof(dst)); Will the second option always ...

c++ memcpy return value

according to http://www.cplusplus.com/reference/clibrary/cstring/memcpy/ c++'s memcpy takes three parameters: destination, source and size/bytes. it also returns a pointer. why is that so? aren't the parameters enough to input and copy data. or am i misunderstanding something? the examples don't use the return value ...

C strange array behaviour

After learning that both strncmp is not what it seems to be and strlcpy not being available on my operating system (Linux), I figured I could try and write it myself. I found a quote from Ulrich Drepper, the libc maintainer, who posted an alternative to strlcpy using mempcpy. I don't have mempcpy either, but it's behaviour was easy to r...

Access Violation

I've been learning how to NOP functions in C++ or even C but there are very few tutorials online about it. I've been googling for the past few hours now and I'm just stuck. Here is my code. #include <iostream> #include <windows.h> #include <tlhelp32.h> using namespace std; //#define NOP 0x90 byte NOP[] = {0x90}; void enableDebugPrivil...

Using memcpy/memset

When using memset or memcpy within an Obj-C program, will the compiler optimise the setting (memset) or copying (memcpy) of data into 32-bit writes or will it do it byte by byte? ...

strcpy v/s memcpy

What is the difference between memcpy() and strcpy()? I tried to find it with the help of a program but both are giving the same output. int main() { char s[5]={'s','a','\0','c','h'}; char p[5]; char t[5]; strcpy(p,s); memcpy(t,s,5); printf("sachin p is [%s], t is [%s]",p,t); return 0; } Output sachin p i...

C++ memcpy from double array to float array

Is is possible to memcpy from a double array to a float array safely? ...

faster alternative to memcpy?

I have a function that is doing memcpy, but it's taking up an enormous amount of cycles. Is there a faster alternative/approach than using memcpy to move a piece of memory? ...

C++ memcpy problem :(

Hey all :) I have a problem my src pointer of memcpy is pointing wrong. unsigned char* lpBuffer is a buffer that contains my bytes, i checked with olly. The code: IMAGE_DOS_HEADER iDOSh; memcpy(&iDOSh,lpBuffer,sizeof(iDOSh)); The problem is that lpBuffer points wrong, output from debugger is dest = 002859E8 RIGHT src = 000001D8 ...

Why is the exception thrown on memcpy using during copying LPBYTE to LPTSTR (clipboard)?

Hello, I have a LPBYTE array (taken from file) and I need to copy it into LPTSRT (actually into the clipboard). The trouble is copying work but unstable, sometime an exception was thrown (not always) and I don't understand why. The code is: FILE *fConnect = _wfopen(connectFilePath, _T("rb")); if (!fConnect) return; fseek(fCo...

CUDA: cudaMemcpy returns cudaErrorInvalidValue for __device__ array

When I define an array on the device (that is initialized with a "Hello" string in this example) and try to copy this to the host, I get the error code cudaErrorInvalidValue. However, from inside a kernel, the d_helloStr[] can be accessed. Referring to the CUDA programming guide chapter B.2.1, such a variable should also be accessible th...

C question related to pointers and arrays

Hi, Basically in the code below, my final array does not seem to have the contents from function1(). Any ideas on why I can't get this to work ? Thanks. #include <stdio.h> #include <string.h> #include<stdlib.h> unsigned char *function1() { unsigned char array2[] = { 0x4a,0xb2 }; return (array2 ); } main() ...

In C, How does memcpy deal with a signed integer argument?

In C, what will happen if I supply a signed integer especifically a negative integer as the 3rd argument to the memcpy function? Example: memcpy(destBuf, source, -100*sizeof(source)) Will the result of -100*sizeof(source) be interpreted by memcpy as unsigned? Thanks! ...

Does memcpy work for large arrays in structures?

I have a structure that has a dynamic array in it. I have defined two of these structures. I fill the array in the first structure, then use a line like memcpy(R->v, A->v, A->n*sizeof(double) where v is the array that has been dynamically allocated, and n is the number of entries. R and A are the same type if that matters. The probl...

mempcy fail to copy all data

Hello all, I encounter problem with memcpy in C. Here is the code : typedef struct { CPY_IM009_DEF }message; message msg; with CPY_IM009_DEF is a struct in other files. Then I try this char wx_msg_buf[8192]; memset(wx_msg_buf, 32, sizeof (wx_msg_buf)); memcpy(wx_msg_buf, &msg, sizeof (msg)); when I check the size : sizeof (msg)...

errors concatenating bytes from a block of bytes using memcpy

On occasion, the following code works, which probably means good concept, but poor execution. Since this crashes depending on where the bits fell, this means I am butchering a step along the way. I am interested in finding an elegant way to fill bufferdata with <=4096 bytes from buffer, but admittedly, this is not it. EDIT: the error ...