转自:http://blog.chinaunix.net/u2/74100/showart_1154283.html
printf() 与 RETAILMSG() 差别
这个printf(),大家可能都是很熟悉的了,而
RETAILMSG()是在evc 下的嵌入式开发 s3c2410,arm9 ,用的,在wince 操作系统下的。
大家在调试信息的时候,一般都会用到这些函数,来显示输出信息;evc 对两个函数也都是支持的。
但是,如果系统对实时性要求高的话,那么这两个函数就会有很大的区别;
printf 函数的所使用的时间要远比RETAILMSG()大的多。printf函数的调用大约要用去100毫秒的时间,而RETAILMSG()用的时间大约10毫秒;
所以在,debug 版本的调试中,在输出信息的地方,能用RETAILMSG()就用RETAILMSG();尽量不用printf;
当然在,realease 版本中,要把所有的输出调试信息的函数尽量都屏蔽掉;方法是通过使用 #ifdef ,如下:
#ifdef DEBUG
printf("/n broadcast Hello");
#endif;
printf("/n broadcast Hello");
#endif;
【or】
#ifdef DEBUG
RETAILMSG(1,(TEXT("Receive a packet/t/n")));
RETAILMSG(1,(TEXT("Receive a packet/t/n")));
#endif;
那么,在debug的版本中,为什么printf函数和RETAILMSG()会有这么大的时间差别呢??
这个问题待研究???????
补充:来自MSDN
RETAILMSG
This macro conditionally outputs a printf-style formatted message.
RETAILMSG (
Expression,
Message
)
第一个参数是bool型,判断是否有效,1有效;第二个参数是相关答应消息!
Parameters
-
Expression
- Boolean expression used to determine if the message would be output. Message
- Expression to be printed using printf format style.
Return Values
None.
Remarks
The printf-style message parameter is output if the Boolean input expression evaluates to TRUE. Note that the parameter Message must be enclosed by parentheses to prevent syntax errors being generated by the preprocessor. This macro should be used sparingly, as it increases the size of retail builds.
Example
RETAILMSG(TRUE, (TEXT("Testing item count against maximum %u/r/n"),
dwMaxNumberOfItems));
RETAILMSG(dwCurrentNumberOfItems >= dwMaxNumberOfItems,
(TEXT("Invalid item count! Found %u, expected less than %u/r/n"),
dwCurrentNumberOfItems, dwMaxNumberOfItems));
dwMaxNumberOfItems));
RETAILMSG(dwCurrentNumberOfItems >= dwMaxNumberOfItems,
(TEXT("Invalid item count! Found %u, expected less than %u/r/n"),
dwCurrentNumberOfItems, dwMaxNumberOfItems));
Output:
Testing item count against maximum 68
Invalid item count! Found 343, expected less than 68
Invalid item count! Found 343, expected less than 68