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

undefined reference on ubuntu using memcpy

In the aData.h file I have struct AnalysisData { Myuint64 maxRegsNeeded; } static const Myuint64 My_NA_Value_64 = (Myuint64) - 1; Myuint64 is defined in the following way : typedef unsigned long long Myuint64 If in the aData.cpp file I…
YAKOVM
  • 9,805
  • 31
  • 116
  • 217
0
votes
3 answers

Memory manipulating - what am I doing wrong?

Right, so I'm playing around with memory moving data around. I'm having trouble here. What can I be doing wrong? I've accounted for the null terminator and it still doesn't output what I expect. char buff[34] = "I will not do anything like…
user1255454
  • 669
  • 1
  • 8
  • 18
0
votes
3 answers

Strange situation related to char[] and memcpy

I am a c++ newbie and just try to write some code to have experiment myself. Recently I have encountered a problem that I cannot debug. char acExpReason[128]; char acReason[] = "An error message is information displayed when an unexpected condition…
GJ.
  • 870
  • 5
  • 9
  • 26
0
votes
2 answers

Sending a struct over UDP sockets memcopy c++

I'm writing a hybrid program that sends a struct containing vectors of sprites from the server to the client when a change has been made (New bullets added, new enemy added, enemy or bullet deleted). The program frequently adds several enemies to…
Staarland
  • 1
  • 1
0
votes
1 answer

cudaHostAlloc memory with cudaHostAllocPortable is not writable in different thread

I'm trying to write to CUDA host memory (which I created in my main thread) with a worker thread. The code for this is very simple. I create the memory with unsigned char* _new; cudaHostAlloc(&_new, _size, cudaHostAllocPortable); and pass the…
Lars
  • 81
  • 1
  • 8
0
votes
1 answer

memcpy on malloc'ed memory is not running well

I'm facing a really weird phenomenon of memcpy. I've allocated a data pointer with 2GB size, but it seems I can't do memcpy when my offset to the pointer is more than 1666800 bytes. Here is the code dataMem = (struct dataRecord*) malloc(memsize *…
0
votes
1 answer

Protobuf message and memcpy inside erlang nif

I'm using protobuf inside nif function (erlang nif) and need to create resource of protobuf message type. I wrote something like this: ERL_NIF_TERM create_resource(ErlNifEnv *env, const MyClass &msg) { size_t size = sizeof(MyClass); MyClass…
Def_NulL
  • 87
  • 4
0
votes
1 answer

What is the most efficient way to convert a string to a char array/ value that a char pointer can point to

If I have a string: std::string Pooptacular = "Pooptacular" and I want to convert it to a char array, I have some options one being: char* poopCArr = Pooptacular.c_str(); or I can do something with memcpy or strcpy and such. What I want to know…
kjh
  • 3,407
  • 8
  • 42
  • 79
0
votes
2 answers

mmap map size limit

Possible Duplicate: Getting segmentation fault SIGSEGV in memcpy after mmap I'm using mmap() in my cpp code to map a large size area (100,000,000 bytes ~ 100MB). From man mmap I understand that I can only know whether it succeeded or not, I…
Bush
  • 2,433
  • 5
  • 34
  • 57
0
votes
1 answer

C++: Program crashes with core dump at [memcpy]

I'm working on Solaris 5.8, C++, using the Json parser. The problem is: while parsing a file of size greater than 700 MB, the process crashes with core dump error. It roughly occurs at below code point - int printbuf_memappend(struct printbuf *p,…
0
votes
1 answer

c++; Is bitset the solution for me?

I am writing a program and using memcpy to copy some bytes of data, using the following code; #define ETH_ALEN 6 unsigned char sourceMAC[6]; unsigned char destMAC[6]; char* txBuffer; .... memcpy((void*)txBuffer, (void*)destMAC,…
jwbensley
  • 10,534
  • 19
  • 75
  • 93
0
votes
2 answers

Why does memcpy not work on second try?

memcpy is behaving in a strange way in my program. My function is called twice, so the memcpy line is run twice, the first time it works no problem and the second time around I get a seg fault at that line (using gdb). I am confused because I don't…
spatara
  • 893
  • 4
  • 15
  • 28
0
votes
3 answers

converting a void * to an array

I need to convert an array an place it in a struct that has a void* element and back to another array: unsigned short array[size]; //do something to the array typedef struct ck{ void * arg1; void * arg2; void * arg3; } argCookie; argCookie…
Mppl
  • 941
  • 10
  • 18
0
votes
3 answers

Can is_trivially_copy_assignable and is_trivially_copy_constructible be exploited for optimization purposes?

It seems that values aren't safe to copy with memcpy unless the type is trivially copyable, i.e. satisfies the std::is_trivially_copyable type trait. I wonder what the purpose of the type traits std::is_trivially_copy_assignable,…
Stephan
  • 117
  • 1
  • 7
0
votes
3 answers

Isn't this code incorrect?

My instructor presents this slide for "matrix copying": #define ROWSIZ 17 #define COLSIZ 27 int enamatrisen[ROWSIZ][COLSIZ]; int andramatrisen[ROWSIZ][COLSIZ]; void matcpy (int* dst, int* src) { int i, j; for (i=0; i
Niklas Rosencrantz
  • 25,640
  • 75
  • 229
  • 424