If I have a char* for example :
and I want to add 0x00 before each byte .Code:{0x01,0x02,0x03,0x04,0x05}
the result will be :
What is the faster way to do that ?Code:{0x00,0x01,0x00,0x02,0x00,0x03,0x00,0x04,0x00,0x05}
If I have a char* for example :
and I want to add 0x00 before each byte .Code:{0x01,0x02,0x03,0x04,0x05}
the result will be :
What is the faster way to do that ?Code:{0x00,0x01,0x00,0x02,0x00,0x03,0x00,0x04,0x00,0x05}
Probably picking up more than one character at a time, which would be processor dependent. In assembly on X86 with xmm registers, you could load 16 bytes at a time, copy to another xmm register, then use pshufb on both xmm registers to insert the zeroes, then store 16 bytes at a time (twice).
Last edited by rcgldr; 01-03-2019 at 01:13 PM.
> What is the faster way to do that ?
Faster than what?
You haven't shown us what you're doing at the moment.
Unless you have some woefully underpowered micro-controller, or needing to do 100's of MB/sec, this looks like a premature optimisation.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
For those of us not familiar with assembly, couldn't the same be achieved by memcpy'ing into a uint16_t pointer? Would probably need to account for endianness though.
EDIT: offtopic, BTW, do u guys know if the forums were under ddos attack? It was hard to access the site the past 24 hours. I was getting this error:
Last edited by Dren; 01-03-2019 at 07:24 PM.