Skip to main content
Filter by
Sorted by
Tagged with
3 votes
2 answers
182 views

I duplicated the topic because (possibly) I made a mistake with the section of the site and initially posted in the wrong place: Ways to reliably read an object in C I have a regular byte buffer ...
Evgeny Ilyin's user avatar
Best practices
1 vote
5 replies
139 views

I have a regular byte buffer declared in file scope: static unsigned char buffer[32]; At some point, the function to start a DMA read operation into this buffer is called: void func(void) { ...
Evgeny Ilyin's user avatar
3 votes
0 answers
92 views

Can I modify host data in host_data_ptr after the following ? cudaMemcpyAsync(device_data_ptr, host_data_ptr, size, cudaMemcpyHostToDevice, ...
YSF's user avatar
  • 41
3 votes
1 answer
160 views

Environment is Ubuntu 24.04, QT Creator 6, g++ 13.3, pthreads. Given the following code (error handling has been removed for readability): #include <iostream> #include <thread> #include &...
Mike's user avatar
  • 629
3 votes
4 answers
231 views

It's a problem I ran into in my work. Our embedded platform is a customized Android OS running on quad-core Cortex-A7. Background: I'm receiving a set of parameters from outside my process, and it's ...
Nathan Weasley's user avatar
8 votes
1 answer
339 views

In the C++ standard the meaning of memcpy is taken from C (I will quote C++23 here but I don't believe the wording has changed from earlier versions): The contents and meaning of the header are the ...
JMC's user avatar
  • 2,123
1 vote
1 answer
177 views

This is not a XY question. I'm curious about what I'm asking. That's it. I'm not going to use std::memcpy() or other things to make copies of non-copyable objects anyway. I know what copyable means, ...
Enlico's user avatar
  • 30.3k
0 votes
0 answers
61 views

I'm working on simulating a Black Hole attack in a TSCH network using Contiki-NG and Cooja (Z1 Motes ) with simple node which exists in the following path "contiki-ng/examples/6tisch/simple-node/...
Haithem Dixon's user avatar
-6 votes
1 answer
156 views

I was exploring memcpy in C++. I have a program that reads 10 bytes from a file called temp.txt. The content of the file is: abcdefghijklmnopqrstuvwxyz Here's the code: // This file is called "...
Tyler Durden's user avatar
0 votes
1 answer
67 views

I have the following short LLVM program that is resulting in a segfault. I'm hoping someone can either tell me why or tell me how I can find out. This is a much simplified version of code generated ...
tarski's user avatar
  • 249
1 vote
1 answer
97 views

There is a problem on Exercism I'm stuck on. I should get the multiples of a factor that are less than the limit and then add them to an array, I should do this to all factors (get their multiples ...
greec_d's user avatar
  • 23
12 votes
1 answer
412 views

Why does C++ std::bit_cast require both To and From to be trivially-copyable? For example: From from{}; To to; static_assert(sizeof to == sizeof from); std::memcpy(&to, &from, sizeof to); ...
lobelk's user avatar
  • 531
0 votes
1 answer
186 views

I meet the same problem with this guy Memcpy from PCIe memory takes more time than memcpy to PCIe memory Yes, MMIO read is very slow at x86/x86-64, only create/send the 32 or 64 bits of TLP payload ...
Hu Mike's user avatar
  • 21
0 votes
4 answers
196 views

P.S I am aware that memcpy should not be used to copy data to an overlapping memory address, and that memmove should be used instead. Based on my understanding of memcpy, the function basically copies ...
eggsac's user avatar
  • 9
-4 votes
1 answer
150 views

I have code that sets each byte of a byte array m individually from an unsigned long long named i. I want to do it in ONE operation using memcpy. So copy the value of i to m, so that each byte of m, ...
Ömer Enes Özmen's user avatar
0 votes
0 answers
94 views

This is a follow up of Bitwise swapping the internal representation of two simple objects, even if they are not of a trivially copyable type. I merely simplify a bit OP snippet and make the considered ...
Oersted's user avatar
  • 3,834
3 votes
2 answers
144 views

This is the code: void *ft_memcpy(void *dst, const void *src, size_t n) { unsigned char *to; unsigned char *from; if (dst == NULL && src == NULL) return (NULL); ...
youssef's user avatar
  • 61
2 votes
1 answer
127 views

I tried to write a C program that would copy a function to other memory location, and then execute it as a function pointer. But I'm facing issues. This is my code: #include <stdio.h> #include &...
Elisa K. K.'s user avatar
4 votes
1 answer
220 views

I'm looking for legit use-cases of std::bit_cast in my code bases. Yet current cppreference documentation makes me wonder if it may induce an overhead by creating a (named) temporary object (thus not ...
Oersted's user avatar
  • 3,834
1 vote
0 answers
47 views

I managed to break backtrace(). I so happend that I can't trace some program crashes like so: void backtrace_init() { struct sigaction sigact; sigact.sa_sigaction = crit_err_hdlr; ...
Андрей Виноградов's user avatar
1 vote
0 answers
185 views

I have a task to implement memcpy function in x86_64 assembler with this signature: extern void* my_memcpy(void* dest, const void* src, uint32_t count); I wrote it: .intel_syntax noprefix .text ....
mackenzie's user avatar
0 votes
0 answers
51 views

I am new to structured text and barely getting started . I need to copy 8 bytes of data I receive over a CAN to another variable in structure in Structured text . Here is my code TYPE msg : UNION ...
pranathi's user avatar
  • 393
1 vote
1 answer
97 views

I have a callee function invoked by a caller function that modifies the contents of a member of a field in a union. This union is nested within a strut, and the struct is globally scoped. However, the ...
Elliott Goldstein's user avatar
0 votes
1 answer
137 views

I'm using an 8 byte shared memory segment in PHP, using shmop_* functions. By looking at PHP's source code, I see that internally shmop_write() and shmop_read() use memcpy() to fill/read those 8 bytes....
Stephen Cantini's user avatar
0 votes
1 answer
113 views

#include <cstring> #include <cstdio> #include <cstdlib> struct Block { int32_t size; u_int8_t data[0]; }; int main(int argc, char **argv) { Block block; Block *ptr =...
EthanLee's user avatar
2 votes
1 answer
126 views

#include <iostream> #include <cstring> #include <bitset> using namespace std; int main() { double tx = 0xFFFF0000FFFF0000; uint64_t tx1 = 0; static_assert(sizeof(...
Handrix's user avatar
  • 23
1 vote
0 answers
207 views

Original question I tested memcpy performance from heap to heap and from heap to shared memory (shm_open). The test codes are as follows: // shm_msg.hpp #ifndef _SHM_MSG_HPP_ #define _SHM_MSG_HPP_ #...
allblue lai's user avatar
1 vote
0 answers
262 views

Recently, we made some optimization attempts in the Native code of a specific app in our company to address performance issues. We released a gray version containing the mentioned modifications to a ...
larry king's user avatar
0 votes
1 answer
120 views

I am making a program which requires multiple types of dynamic arrays in C89. What I am trying to do is create my own implementation of a dynamic array that supports custom struct data. However, while ...
Jagger Harris's user avatar
5 votes
1 answer
230 views

Say you have a type that is trivially copyable, not an aggregate, and not trivially constructible: struct Foo { Foo() = default; Foo(int i) : a(i) {}; int a = 5; }; Foo isn't an ...
James Picone's user avatar
  • 1,619
4 votes
2 answers
133 views

If two pointers are pointing to the same struct variable, is it defined behaviour to assign one dereferenced pointer to the other? struct Struct { int member; }; int main() { struct Struct s, ...
Michael Jones's user avatar
0 votes
1 answer
134 views

I have 2 classes. Pointer to an array of fixed width and Pointer to a Pointer for implementing 2d array of floats. I wanted to understand, if and how can I use memcpy for my Copy constructor and ...
Sourabh's user avatar
  • 787
0 votes
0 answers
341 views

Recently, when I make a Linux device driver and memcpy memory obtained with mmap, the Linux kernel has a bus error and I ask questions. Here's the code that caused the problem typedef struct buffer_t {...
roqkftoqkfwk's user avatar
-1 votes
2 answers
121 views

I have declared 2 strings i.e string1 and string2. string1 is of size 8 and string2 is of size 200. Now, I am trying to copy string2 to string1. string1 has lesser size than string2. And I am copying ...
Subhadip's user avatar
  • 461
3 votes
1 answer
256 views

It is stated on cppref that If either dest or src is an invalid or null pointer, the behavior is undefined, even if count is zero Same is stated for memset and memmove. My question is: where is it ...
Senua's user avatar
  • 586
1 vote
0 answers
145 views

Lets say I have a large, non-Copy, stack allocated data structure, and then I move it a bunch of times: struct Foo(u8); fn main() { // A big (8MiB) stack allocation let big_stack_data: [Foo; ...
RBF06's user avatar
  • 2,501
-2 votes
3 answers
436 views

I've got some legacy code containing the following line of code: uint16_t* data = reinterpret_cast<uint16_t*>(array_.data()); // #1 With array_ of type std::vector. So far, I understood that we ...
LPo's user avatar
  • 95
4 votes
2 answers
133 views

Say I have the following code: char buff[100] = {0}; char msg[] = "hello!"; memcpy(buff, msg, sizeof(msg)); OR memcpy(&buff, msg, sizeof(msg)); Why do the two memcpy lines work ...
RemyBean's user avatar
1 vote
0 answers
65 views

The C script uses dirent to fetch directories and stores paths fetched and files: // Packages #include <dirent.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #...
Elia Riva's user avatar
-1 votes
1 answer
105 views

I want to copy some part of data into source_mac This is my code: uint8_t *data uint8_t *source_mac memcpy(&source_mac, &data[6], 6); So I want to copy 6 bytes from data, starting with the ...
hannah's user avatar
  • 1
0 votes
0 answers
167 views

In c++ I have the following piece of code, that is optimised in assembly to call memcpy. void do_something(big_struct& a, const big_struct& b) { a = b; } lea rdi,[rsi+0x4] mov edx,...
Chuu's user avatar
  • 4,601
-3 votes
1 answer
423 views

In a legacy code I am getting buffer overflow errors in fortify audit. Let me explain the issue here: I have a function, say foo(size_t len, unsigned char **buf) ,in this foo I am memcopying a string ...
RC0993's user avatar
  • 978
-1 votes
1 answer
214 views

I'm using SYCL on Intel Develope Cloud to test Innovative algorithms. My questions: SYCL q.memcpy() & h.memcpy() do not work. It seems that Intel know about it What is the status of this issue? ...
Ami's user avatar
  • 21
0 votes
3 answers
1k views

A few posts compare the performance between C++-style functions std::copy, std::equal, std::fill with C-style functions std::memcpy, std::memcmp, std::memset, for example : memcpy vs std::copy, ...
kingsjester's user avatar
2 votes
0 answers
175 views

Assuming some insane person designs an FPGA to produce a SIGBUS signal occasionally on valid memcpy accesses to mmapd addresses, as a weird way to communicate up, what is the best way to reset the ...
fm_user8's user avatar
  • 448
-1 votes
2 answers
235 views

Everything I have read suggests that memcpy does not throw an exception so try-catch statements cannot be used to handle such an error. I have been provided memory addresses and ranges by the ...
fm_user8's user avatar
  • 448
4 votes
0 answers
213 views

I want to use the non-temporary instruction to reduce the read bandwidth generated by write allocate during the memcpy process. The expected read and write bandwidth after optimization should be the ...
Frontier_Setter's user avatar
0 votes
1 answer
125 views

The following code gives a crash stating double free. How to fix this with leaving no memory leaks? Trying to copy contents of tmp to list. Removing free from get_copy gives no crash. But that will ...
LostProgrammer's user avatar
0 votes
0 answers
76 views

I've been experimenting with memcpy() implementations and optimizations in C; I recently wrote a version which was supposed to use successive powers-of-two to speed up the copy: first, large 8-byte ...
ecfedele's user avatar
  • 316
0 votes
2 answers
100 views

In the code I am working on, I need to do the following: Create a map where each value is buffer of fixed size Use memcpy to populate one element of one value of the map (that is, one element of an ...
Nathan Goedeke's user avatar

1
2 3 4 5
33