Yes, at the very least you waste code cache space to store something non-executable. For optimization the best option is to take the time to declare the string somewhere else (like HLLs compilers do, but here you have to do it manually). Also, the stack adjustment sometimes can be omitted (for instance if you are about to use leave instruction), but the macro will always use "add esp, ...", so for maximum optimization, macros should not be used unless the code they will create is already the very same one you'd do by hand.
To avoid having to declare the strings manually and still have them all together outside the code the cinvoke, invoke, stdcall, ccall, and any other macros of this kind I may missing could be extended to check for string parameters and build up a list of strings and then have a another macro which store them at the place of invocation, and when them detect that the separate store was used then they'll use them, otherwise will continue with the same pattern described above.
PS: Another disadvantage of storing the string like above is that you mess up the return address buffer, so when printf returns the CPU will mispredict the return address.
|