常数值与#定义,哪一种芯片资源将被使用? [英] const value vs. #define, which kind of chip resource will be used?

查看:109
本文介绍了常数值与#定义,哪一种芯片资源将被使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我定义一个宏,或使用静态常量的值,在嵌入式系统中,

哪一种将使用内存,闪存芯片或芯片内存?
哪种方式更好呢?

if I define a macro, or use static const value, in an embedded system,
which kind of memory will be used, chip flash or chip ram? Which way is better?

推荐答案

好吧,如果你#定义一个宏,不需要额外的内存或code空间(闪存)为它分配的。所有的工作在编译阶段完成的。

Well, if you #define a macro, no additional memory or code space (flash) allocated for it. All job done in compile stage.

如果您使用的是静态常量全局变量,二进制codeS将为分配给它的初始值和内存中产生。两个闪光灯(bin文件尺寸较大)和使用的内存(RAM芯片)。

If you use a static const global variable, binary codes will generated for initial value and memory allocated for it. both flash (bin file size bigger) and memory (chip ram) used.

这篇关于常数值与#定义,哪一种芯片资源将被使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆