c - function pointer vs. macro vs. inline -


i have function checks , reads arrays of bytes:

uint8 readmem(uint16 addr) {     if (addr >= 0x8000) return rom[addr];     if (addr <  0x2000) return ram[addr];     // more complex checks here     return open_bus; } 

since it's used emulator core, it's called millions of times per second. wonder overhead in general, compared 3 options: inline, macro , calling pointer.

the first 2 options aren't good, because function isn't small, , it's called one, that's embedded of opcodes, , if being inlined, dramatically increases compilation time , exe size. , test how function pointer work, i'd have refactoring. there's option compile core once, separately rest emulator, it'd require refactoring.

so worth refactoring in end? call pointer fast macro or inline, or maybe it'll faster? pitfalls each method wouldn't important probably, since function quite simple, it's bit long. , frequent.

function pointer vs. macro vs. inline

macro -> compile time resolved inline -> compile time resolved function pointer -> runtime resolved 
  1. macro , inline contents replaced @ preprocessor stage , fast. not change @ runtime disadvantage.
  2. function pointer hold address of function. useful passing function address function or calling function using function pointer.this process takes time more. because of internally has been done push/pop operation in stack.