c++ - Fast way to convert type between char* to custom union -


i have 2 types , 1 function. 1 type

char one[32] 

the other type

typedef union _data{     uint8 byte[32];     int8  ibyte[32]; }data 

the function gets data input parameter,

void compute(data data){}

now, have char* (char[32]) type , wish convert data type , pass parameter compute. both types 32byte size, , want fast way convert type.
thought of memcpy,but slow since copies data.
can use pointer somehow pass char* data type?

the way of doing without breaking strict aliasing , being well-defined copy character array correct array of union.

perhaps like

data data; if (std::is_signed<char>::value) {     std::copy_n(one, 32, data.ibyte); } else {     std::copy_n(one, 32, data.byte); } 

and no it's not going "slow", unless thousands of time per second. measure , profile first, don't fall trap of premature optimization.


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -