faster alternative to memcpy?

后端 未结 16 1155
一生所求
一生所求 2020-11-29 21:27

I have a function that is doing memcpy, but it\'s taking up an enormous amount of cycles. Is there a faster alternative/approach than using memcpy to move a piece of memory?

16条回答
  •  执念已碎
    2020-11-29 21:31

    Actually, memcpy is NOT the fastest way, especially if you call it many times. I also had some code that I really needed to speed up, and memcpy is slow because it has too many unnecessary checks. For example, it checks to see if the destination and source memory blocks overlap and if it should start copying from the back of the block rather than the front. If you do not care about such considerations, you can certainly do significantly better. I have some code, but here is perhaps an ever better version:

    Very fast memcpy for image processing?.

    If you search, you can find other implementations as well. But for true speed you need an assembly version.

提交回复
热议问题