2 ms·
Actually you can do the following (example is a hypothetical memory allocator implemented at least partially in asm): 1) create a "meta header file" malloc.h,
by mschuster91 13y ago
Actually you can do the following (example is a hypothetical memory allocator implemented at least partially in asm):
1) create a "meta header file" malloc.h, containing the function prototypes.
2) create a "meta source file" malloc.cpp, with #ifdef switches for e.g. x86, x86_64, arm, etc, and inside the ifdefs some #include "malloc_x86.cpp"
3) inside the malloc_x.cpp source files, implement your architecture-specific asm code.
4) if you're after portable code, just do a #else #include "malloc_c.cpp" with a pure-c/cpp implementation. This way everyone can use the malloc and those with matching CPUs can benefit from acceleration.