简体   繁体   中英

IPv6 address copy optimization in C

since memcpy should be highly optimized nowadays, does it still make sense to optimize the copy of Ipv6 addresses using explicit loop unrolling ?

#include <netinet/in.h>

struct in6_addr IP_1;
struct in6_addr IP_2;
;
;
IP2.__in6_u.__u6_addr32[0] = IP1.__in6_u.__u6_addr32[0];
IP2.__in6_u.__u6_addr32[1] = IP1.__in6_u.__u6_addr32[1];
IP2.__in6_u.__u6_addr32[2] = IP1.__in6_u.__u6_addr32[2];
IP2.__in6_u.__u6_addr32[3] = IP1.__in6_u.__u6_addr32[3];

Note that the code above is best suited for 32-bit architectures.

Is there a best practice I do not know ?

You should just do IP2 = IP1; , and let the compiler deal with it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM