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

Copying unsigned char array to uint32_t, and vice versa

I'm trying to iteratively copy an unsigned char array to a uint_32t variable (in 4 byte blocks), perform some operation on the uint_32t variable, and copy it back to the unsigned char array. Here's my code: unsigned char byteArray[len] for (int…
user1118764
  • 9,255
  • 18
  • 61
  • 113
-1
votes
1 answer

How would I get convert this std::string into a std::basic string?

Currently I have a std:::string called cipher_line that I get from the process of: string str_cipher_line; // Get the Offline Mount Point ifstream ifs1; ifs1.open(offlineMountPoint.c_str()); if (ifs1.is_open()) { getline(ifs1,…
SDG
  • 2,260
  • 8
  • 35
  • 77
-1
votes
2 answers

Am I really copying the bytes or am I copying characters in this case?

I have a vector of unsigned char where I copy bytes in C++. I convert all primitive types to bytes and copy to this vector of char (which is interpreted as bytes in C++). Now I am copying also strings. But I am not sure if I am converting strings to…
Felipe
  • 7,013
  • 8
  • 44
  • 102
-1
votes
1 answer

memcpy () : Access violation writing location

I am getting Access violation writing location 0xB7066CBC while running this code.Unable to figure out whats going on, any suggestions? int main(void) { unsigned int SIG = 0x00000000; unsigned int *base = (unsigned int *)0xb7066CBC; SIG =…
Kalangu
  • 135
  • 10
-1
votes
1 answer

memcpy from a vector to void pointer (vice-versa) not working

This is struct node with 2 variables. typedef struct{ int a; int b; }node; Inserting the values into vector of the node type. vector nv; node n; n.a = 10; n.b = 20; nv.push_back(n); n.a = 100; n.b =…
-1
votes
1 answer

copying a struct in a function and returning the copy in c

I am implementing a queue using a generic linked list in C where each node in list is a simple struct which contains a void pointer and a node pointer to the next node. In the dequeue operation I want to remove the head (which is working fine), but…
K.A.Q
  • 469
  • 4
  • 13
-1
votes
1 answer

heap corruption when using pin_ptr to copy from native code to managed code

I am trying to copy unsigned short from native code to managed code, but I get a heap corruption when calling memcpy. INPUT: unsigned short* input OUTPUT: array output I have the following code and if I set testDataSize is 100 then…
user1296153
  • 575
  • 6
  • 23
-1
votes
1 answer

why is that the for loop terminates but the memcpy within copies the same substring?

My assignment asks us to shorten the words of an user input sentence. Then put the shortened words into a linked list. When the gears of code get stuck: the last word in the sentence gets saved into every node. What repair should be implemented so…
-1
votes
1 answer

memcpy unsigned char to int

I'm trying to get an int value from a file I read. The trick is that I don't know how many bytes this value lays on, so I first read the length octet, then try to read as many data bytes as length octet tells me. The issue comes when I try to put…
veliki
  • 41
  • 1
  • 8
-1
votes
1 answer

Eventual ARM Linux Memory Fragmentation with NEON Copy but not memcpy

I am running Linux 4.4 on a BeagleBone X-15 ( ARM Cortex-A15 ) board. My application mmaps the output of the SGX GPU and needs to copy the DRM backing store. Both memcpy and my custom NEON copy code work... but the NEON code is much faster ( ~11ms…
PhilBot
  • 748
  • 18
  • 85
  • 173
-1
votes
1 answer

Copy array via memcpy

I saw there are a lot of articles about memcpy but I can't find the solution for my problem. Can somebody see why the copy action doesn't work? float MeanFilter(const volatile float *Array, volatile float Dist){ float Avg = 0.0; // Variable used…
NickDR92
  • 11
  • 5
-1
votes
1 answer

how can i read one memory byte

Here is memory block I'm working with: You can see 8b ff 55 8b ec 83 7d 0c 01 . . . . code. I want to get one each byte, so I tried: DWORD offset; // this memroy has '0x61CAB0E4' and that means '8b ff 55... memroy block' BYTE…
mwK
  • 1
  • 6
-1
votes
1 answer

Recreating strlcat function in C "invalid operands to binary expression ('size_t' (aka 'unsigned long') and 'char *')"

I'm trying to recreate my strlcat function from the C function library. I was looking around on the internet how it works. Basically, strlcat allows appending your source string into destination string with a NUL-terminated. The return value must…
Zeid Tisnes
  • 396
  • 5
  • 22
-1
votes
1 answer

C++ Why does my code for overwriting const int x = *(&y); work?

Why does my code for overwriting const int variable work? Is it safe? #include #include using namespace std; int z = 5; const int x = *(&z); int main() { cout << "A:" << x << ", " << &x << endl; int y = 7; cout <<…
Nivs
  • 25
  • 5
-1
votes
3 answers

faster way than memcpy to copy 0-terminated string

I have a question about duplicating a 0-terminated string: const char * str = "Hello World !"; size_t getSize = strlen(str); char * temp = new char[getSize + 1]; ... i know i can use this function memcpy(temp, str, getSize); but i want to use my…
myOwnWays
  • 59
  • 4