为什么cfs_write()会消耗太多的ROM内存?

时间:2022-01-05 21:17:24

I am developing a Contiki application and I am running out of ROM memory. I want to use the Contiki File System (CFS) to write a small file (32 bytes long), so I add the following code:

我正在开发一个Contiki应用程序,我的ROM内存不足。我想使用Contiki文件系统(CFS)写一个小文件(32个字节长),所以我添加以下代码:

 fd_write = cfs_open(filename, CFS_WRITE);
 n = cfs_write(fd_write, message, sizeof(message)); //Message size is 32 bytes
 cfs_close(fd_write);

The problem is that cfs_write() increases the .text section by 3210 bytes. I find about that because the code size removing cfs_write() is:

问题是cfs_write()将.text部分增加了3210个字节。我找到了,因为删除cfs_write()的代码大小是:

  text   data    bss    dec    hex filename
  23912    114   4710  28736   7040 coffee-example.sky

and with cfs_write() the code size is:

并使用cfs_write()代码大小为:

 text   data    bss    dec    hex filename
 27122    114   4710  31946   7cca coffee-example.sky

Notice that cfs_write() increases the .text section by 3210 bytes. Why cfs_write() increases the .text section so much? How can I reduce the size of cfs_write() in the .text section?

请注意,cfs_write()将.text节增加了3210个字节。为什么cfs_write()会如此增加.text段?如何减小.text部分中cfs_write()的大小?

Best regards,

最好的祝福,

Sergio Diaz

塞尔吉奥迪亚兹

1 个解决方案

#1


2  

While cfs_write() is not a huge function on its own, it does call other functions. If you use cfs_write() from the application code, all these other functions are also linked in the executable.

虽然cfs_write()本身不是一个庞大的函数,但它确实调用了其他函数。如果您使用应用程序代码中的cfs_write(),则所有这些其他函数也会链接到可执行文件中。

For example, if you're using the Coffee implementation of CFS (there are multiple implementations), it calls merge_log(), which in turn calls a bunch of functions on its own.

例如,如果您正在使用CFS的Coffee实现(有多个实现),它会调用merge_log(),而merge_log()又会自行调用一堆函数。

There is no easy way to optimize this usage, as the CFS code is already developed with the goal of producing compact binary code in mind.

没有简单的方法可以优化这种用法,因为CFS代码的开发目的是为了生成紧凑的二进制代码。

#1


2  

While cfs_write() is not a huge function on its own, it does call other functions. If you use cfs_write() from the application code, all these other functions are also linked in the executable.

虽然cfs_write()本身不是一个庞大的函数,但它确实调用了其他函数。如果您使用应用程序代码中的cfs_write(),则所有这些其他函数也会链接到可执行文件中。

For example, if you're using the Coffee implementation of CFS (there are multiple implementations), it calls merge_log(), which in turn calls a bunch of functions on its own.

例如,如果您正在使用CFS的Coffee实现(有多个实现),它会调用merge_log(),而merge_log()又会自行调用一堆函数。

There is no easy way to optimize this usage, as the CFS code is already developed with the goal of producing compact binary code in mind.

没有简单的方法可以优化这种用法,因为CFS代码的开发目的是为了生成紧凑的二进制代码。