简体   繁体   中英

What HW resource is mostly used when one does memcpy()?

This feels like a very newbie question, but I suddenly find myself clueless. I'm trying to profile ac application that does a lot of memory copies, and there is an option for me to reduce that number (requires some re-design). I'm trying to realize if it's worth it, but I have no idea what resource it will affect, or how to monitor it.

If someone knows what resource (and how to monitor it in Linux), and/or has a reference to a section in Agner or any other optimization manual I would very much appreciate it. Thanks.

memcpy uses the CPU in order to copy memory from one buffer to the other. Generally speaking, code doing lots of memcpy will be CPU bound.

With that said, some of the underlying design might make this different. In particular, if you're doing a lot of memory copying, it might be that you are using memory once and throwing it away. If that's the case, you are making poor use of the CPU's data cache. Switching to an algorithm that keeps the memory where it is may give you a huge benefit on that front.

As for profiling, I know valgrind has a tool for checking cache efficiency. Maybe others too.

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