faster alternative to memcpy?

后端 未结 16 1179
一生所求
一生所求 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:39

    Sometimes functions like memcpy, memset, ... are implemented in two different ways:

    • once as a real function
    • once as some assembly that's immediately inlined

    Not all compilers take the inlined-assembly version by default, your compiler may use the function variant by default, causing some overhead because of the function call. Check your compiler to see how to take the intrinsic variant of the function (command line option, pragma's, ...).

    Edit: See http://msdn.microsoft.com/en-us/library/tzkfha43%28VS.80%29.aspx for an explanation of intrinsics on the Microsoft C compiler.

提交回复
热议问题