Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1
I think memcpy should work no matter whether you use normal or packed syructs. The size of the struct and therefore the number of bytes you need to copy might be different. And since struct packing is automatically done by the compiler in oder to increase the runtime performance (at the cost of a few bytes) there's no other method than to use some weird locking compiler instruction like __attribute__((__packed__)). If you want to do this safely you need to use Rust I guess. Unlike C Rust can guarantee you that your code is memory safe at compile time, so no performance is lost at runtime.
31st Mar 2020, 5:50 PM
Aaron Eberhardt
Aaron Eberhardt - avatar