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

Is it safe to use memcpy to shift elements in an array?

Let's say I have an integer array that contains junk and data. I wish to shift this array such that the data is at the start of the array. Current: [?, ?, ?, ?, 1, 1, 1, 1, 1] ---------- ------------- JUNK DATA Desired: [1, 1, 1, 1, 1, ?,…
Izzo
  • 4,461
  • 13
  • 45
  • 82
-1
votes
1 answer

Delete struct written with memcpy

I have an assignment on memory blocks. We have a struct Record that I need to save in these memory blocks. Each block holds 5 Records, which i memcpy one after another in a list of blocks and an int CountOfRecords. We also have a DeleteRecord…
-1
votes
2 answers

How can I make a copy of a queue in C?

I'm trying to COPY a queue into another queue in order that if I destroy one, it doesn't destroy the other one. I tried using memcpy this way: memcpy(queue1, queue2, sizeof(queue2)); But I get the following error: expected ‘void * restrict’ but…
user157629
  • 624
  • 4
  • 17
-1
votes
2 answers

Issue concatenating multiple strings with null terminators in-between using memcpy

I'm trying to use memcpy as a strncat since i need to preserve the null terminators in the strings I'm having a rough time trying to understand what i'm missing in this code, I don't know how to check it but i don't think the final string is…
ProdigySR
  • 11
  • 6
-1
votes
1 answer

SIGSEGV, Segmentation fault with memcpy_avx_unaligned

I am trying to copy 4 bytes form s to handler->data didn't understand the error. Tried to debug with gdb, but everything looks good. memcpy(handler->data + handler->len, s->begin, num_bytes); (gdb) p handler->data $5 = (uint8_t *) 0x0 (gdb)…
Nabz C
  • 538
  • 1
  • 9
  • 28
-1
votes
1 answer

Qt: memcpy failed.. How to copy?

My question today is about Qt and the memcpy() function.. I got a QByteArray i_byte_array containing my raw data that I need. First thing I tried is to copy those data in a char* l_array. Which gives me: void blablafunctionblabla(const QByteArray&…
SquadOne
  • 3
  • 4
-1
votes
1 answer

How to Memcopy and copy back to a char array?

I would like to copy a variable of 1 byte to relatively larger char array, and copy it back? How can I do that? /* memcpy example */ #include #include struct Data { unsigned char name[40]; int age; }; typedef unsigned char…
Meric Ozcan
  • 678
  • 5
  • 25
-1
votes
2 answers

How can I understand this code defined in C program?

I have 3 arrays A1, A2, A3 defined in C program, with size of 1500, 980, 980 respectively. A1 initialized by the indices of elements in ascending order, A2 - by the indices too, but in descending order. At the moment after initialization of A1 and…
cricri
  • 1
-1
votes
1 answer

C/C++ memcpu benchmark: measuring CPU and wall time

How can one benchmark memcpy? I wrote test code, but it finishes immediately (probably, due to compiler optimization) and does not actually allocate memory: void test(void) { const uint32_t size = 4000'000'000; char a[size], b[size]; …
S.V
  • 2,149
  • 2
  • 18
  • 41
-1
votes
1 answer

cudamemcpyasync, memcpy fails to copy inside kernel while direct copying works

I am trying to copy from a source float array(containing 1.0f) to a destination float array(containing 2.0f) inside a cuda kernel. I try three different ways using: cudamemcpysync memcpy direct copy (dst[i] = src[i]) When i read the results after…
user27665
  • 673
  • 7
  • 27
-1
votes
3 answers

Copying arbitrary bits from an array into a variable?

so I am working with a data set that comes in as an array. For example: {0x00, 0x00, 0xFF, 0xF1, 0x6D, 0xA2, 0x00 0x00} {0b00000000, 0b00000000, 0b11111111, 0b11110001, 0b01101101, 0b10100010, 0b00000000, 0b00000000} I need to be able to extract…
Punchki
  • 441
  • 1
  • 5
  • 9
-1
votes
2 answers

How to change array member of a structure in C

I am trying to program a microcontroller to be able to communicate with external flash memory chip which utilizes SPI. The operation code (opcode) followed by address bytes then data bytes has to be sent in order. Instead of defining these bytes…
John Lenon
  • 13
  • 2
-1
votes
1 answer

CUDA in C: How to fix Error 11 with cudaMemcpyAsync

I am currently trying to get a simple multi-GPU program running with CUDA. What it basically does is it copies a large array with some dummy data in chunks to the GPUs, which do some math, and then copy the resulting array back. I dont get any…
-1
votes
3 answers

memcpy() does not stop copying

Possible Duplicate: Problem when copying memory (tuple1 and tuple2 are void pointers passed to this function) char *data; data = (char*) calloc (84, 1); memcpy(data, tuple1, 44); memcpy(data+44, tuple2, 40); I have allocated 84 bytes for…
Ivan Kolev
  • 1
  • 1
  • 1
-1
votes
1 answer

using memset() and memcpy() function

// CPP Program to find all the common characters // in n strings #include using namespace std; const int MAX_CHAR = 26; void commonCharacters(string str[], int n) { // primary array for common characters // we assume…