memcpy Questions

7

Solved

In C, you can use strdup to succinctly allocate a buffer and copy a string into it. As far as I'm aware, however, there is no similar function for general memory. For example, I can't say struct m...
Submariner asked 1/12, 2012 at 20:49

12

Solved

I am trying to understand the difference between memcpy() and memmove(), and I have read the text that memcpy() doesn't take care of the overlapping source and destination whereas memmove() does. H...
Schweiz asked 11/12, 2010 at 8:34

8

Solved

I am doing image processing in C that requires copying large chunks of data around memory - the source and destination never overlap. What is the absolute fastest way to do this on the x86 platfor...
Barmecide asked 11/11, 2009 at 13:40

3

I'm trying to create my own versions of C functions and when I got to memcpy and memset I assumed that I should cast the destination and sources pointers to char *. However, I've seen many ex...
Dysteleology asked 9/2, 2023 at 14:59

2

In C and C++, is it undefined behavior to memcpy into a const variable when the number of bytes to be copied is zero? int x = 0; const int foo = 0; memcpy( (void *)&foo, &x, 0 ); This ques...
Silkweed asked 9/10, 2022 at 14:35

3

Solved

I have a buffer that I use for UART, which is declared this way: union Eusart_Buff { uint8_t b8[16]; uint16_t b9[16]; }; struct Eusart_Msg { uint8_t msg_posn; uint8_t msg_len; union Eusart_B...
Bucentaur asked 2/3, 2019 at 23:38

0

C17 says the following about memcpy [7.24.2.1p2]: 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 ...
Strategic asked 24/5, 2022 at 2:22

5

Solved

At first I have this simple protobuf file message messagetest { ... repeated float samples = 6; .... } Which creates a headerfile with this methods //repeated float samples = 6; inline int sa...
Avon asked 19/3, 2013 at 12:32

4

Solved

I'm trying to build an application as tiny as possible, and in doing so I'm trying to avoid use of the CRT by using Win API calls instead of standard C/C++ calls. Unfortunately, I'm still getting a...
Brotherly asked 27/1, 2014 at 3:26

4

I would like to know is it possible to do memcpy by bits instead of bytes? I am writing a C code for Ethernet frame with VLAN tagging, in which I need to fill different values for VLAN header attr...
Aluino asked 26/6, 2013 at 12:55

16

Solved

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?
Gui asked 3/6, 2010 at 7:5

3

Solved

I am trying to allocate AVFrame->data[0] of a video frame to uint8_t* buffer using the following lines of code : size_t sizeOfFrameData = mpAVFrameInput->linesize[0] * mpAVFrameInput->heig...
Iorgo asked 27/3, 2015 at 9:55

6

How can I access s[7] in s? I didn't observe any difference between strncpy and memcpy. If I want to print the output s, along with s[7] (like qwertyA), what are the changes I have to made in the f...
Ibert asked 4/1, 2011 at 13:6

1

Solved

I'm trying to copy one 2D array to another using memcpy. My code: #include <stdio.h> #include <string.h> int print(int arr[][3], int n) { for (int r = 0; r < 3; ++r) { for (int c ...
Tung asked 25/9, 2021 at 19:20

2

Solved

I have always been told(In books and tutorials) that while copying data from kernel space to user space, we should use copy_to_user() and using memcpy() would cause problems to the system. Recently...
Jiggle asked 20/2, 2013 at 1:20

9

Solved

I have a database that stores JSON, and a server that provides an external API to whereby through an HTTP post, values in this database can be changed. The database is used by different processes i...
Swetlana asked 17/7, 2012 at 17:43

7

Solved

I am attempting to copy the members of a struct containing a mixture of ints, char's and arrays of chars into a byte array to send to a serial line. So far I have struct msg_on_send { char descri...
Directorate asked 27/1, 2009 at 17:29

0

Checkout Edit3 I was getting the wrong results because I was measuring without including prefetch triggered events as discussed here. That being said AFAIK I am only see a reduction in RFO requests...

2

Solved

I am compiling this code for a Cortex M7 using GCC: // copy manually void write_test_plain(uint8_t * ptr, uint32_t value) { *ptr++ = (u8)(value); *ptr++ = (u8)(value >> 8); *ptr++ = (u8)(...
Eller asked 14/6, 2018 at 22:35

1

Solved

I was experimenting with pointer manipulation and decided to try converting an array of numbers into an integer by directly copying from memory using memcpy. char aux[4] = {1,2,3,4}; int aux2 = 0;...
Killam asked 9/2, 2021 at 18:53

1

Solved

C++11 introduced std::begin(std::valarray&) as well as std::end(std::valarray&). C++17 introduced std::data() which works with std::vector, std::array, C-style arrays, etc. But why wasn't a...
Hyperextension asked 6/2, 2021 at 0:46

2

Solved

I'm developing a multicore, multithreaded software library in which I want to offer update-order preserving lock-free shared memory objects that might span multiple cache lines. Specifically, sup...
Cohort asked 27/8, 2018 at 16:9

5

Solved

I'm currently using GCC 4.5.3, compiled for PowerPC 440, and am compiling some code that doesn't require libc. I don't have any direct calls to memcpy(), but the compiler seems to be inserting one ...
Alexiaalexin asked 20/6, 2011 at 11:43

3

Solved

When copying a known struct in memory, would you prefer using memcpy or dereference? why? Specifically, in the following code: #include <stdio.h> #include <string.h> typedef struct {...
Chavers asked 11/9, 2012 at 6:22

3

Our task is intended to demonstrate the benefit of using DMA to copy a large amount of data versus relying on the processor to directly handle the copying. The processor is an STM32F407 on the ST d...
Accurate asked 14/5, 2019 at 4:14

© 2022 - 2024 — McMap. All rights reserved.