我正在开发一个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);
问题是cfs_write()会将.text部分增加3210个字节。我找到了这个,因为删除cfs_write()的代码大小是:
text data bss dec hex filename
23912 114 4710 28736 7040 coffee-example.sky
并且使用cfs_write()代码大小为:
text data bss dec hex filename
27122 114 4710 31946 7cca coffee-example.sky
请注意,cfs_write()会将.text部分增加3210个字节。为什么cfs_write()会增加.text部分呢?如何减小.text部分中cfs_write()的大小?
致以最诚挚的问候,
Sergio Diaz
答案 0 :(得分:2)
虽然cfs_write()
本身并不是一个庞大的功能,但它会调用其他函数。如果您从应用程序代码中使用cfs_write()
,则所有这些其他函数也会链接在可执行文件中。
例如,如果您正在使用CFS的Coffee实现(有多个实现),它会调用merge_log()
,而public class Product {
private long id;
private long barcode;
private String description;
private String zone;
private int quantity;
Supplier supplierName;
public Product(){
}
public Product(long id, long barcode, String description, String zone,
int quantity, Supplier supplierName) {
super();
this.id = id;
this.barcode = barcode;
this.description = description;
this.zone = zone;
this.quantity = quantity;
this.supplierName = supplierName;
}
又会自行调用一堆函数。
没有简单的方法来优化这种用法,因为CFS代码的开发目的是为了生成紧凑的二进制代码。