I want to replace memcpy with my own optimized version to do some benchmarks.
I wouldn’t like to modify each place in code which calls memcpy(it’s a large code base and I want to avoid lots of changes). So what I did is the following:
// in a "common" header file which is included everywhere
#ifdef SHOULD_OPTIMIZE
#define memcpy my_on_steroids_memcpy
#endif
The above works and replaces memcpy with my own implementation but it seems crude, forced and not safe at all. Is it any other alternative so that I could replace the library memcpy without modifying the rest of the code? Should I forget about the above as it does not seem an adviseable thing to do and just modify all the other files(and why)?
I just found another way to replace the
memcpyfunction call. It only works with GCC(I still need to find another way for VC++) but I think it’s definitely better than the crude#defineway. It uses the__REDIRECTmacro(insys/cdefs.hincluded viafeatures.h), which from what I’ve seen it’s used extensively in the glibc. Below follows an example with a small test: