【发布时间】:2014-04-16 12:04:28
【问题描述】:
我有一些记忆问题。在这个函数中是否可以减少编译程序的内存?
它使用时间变量 {hh,mm,ss.0} 进行一些计算并返回取决于当前进度 (_SHOOT_COUNT) 的时间(在 millis 中)
unsigned long hour_koef=3600000L;
unsigned long min_koef=60000;
unsigned long timeToMillis(int* time)
{
return (hour_koef*time[0]+min_koef*time[1]+1000*time[2]+100*time[3]);
}
float Func1(float x)
{
return (x*x)/(x*x+(1-x)*(1-x));
}
float EaseFunction(byte percent,byte type)
{
if(type==0)
return Func1(float(percent)/100);
}
unsigned long DelayEasyControl()
{
long dd=timeToMillis(D1);
long dINfrom=timeToMillis(Din);
long dOUTto=timeToMillis(Dout);
if(easyINmode==0 && easyOUTmode==0) return dd;
if(easyINmode==1 && easyOUTmode==0)
{
if(_SHOOT_COUNT<duration) return (dINfrom+(dd-dINfrom)*EaseFunction(_SHOOT_COUNT*100/duration,0));
else return dd;
}
if(easyOUTmode==1)
{
if(_SHOOT_COUNT>=_SHOOT_activation && _SHOOT_activation!=-1)
{
if((_SHOOT_COUNT-_SHOOT_activation)<current_settings.delay_easyOUT_duration) return (dOUTto-(dOUTto-dd)*(1-EaseFunction((_SHOOT_COUNT-_SHOOT_activation)*100/duration,0)));
else return dOUTto;
}
else
{
if(easyINmode==0) return dd;
else if(_SHOOT_COUNT<duration) return (dINfrom+(dd-dINfrom)*EaseFunction(_SHOOT_COUNT*90/duration,0));
else return dd;
}
}
}
【问题讨论】:
-
我在这里看不到单个内存分配。
EaseFunction是做什么的?您是如何得出此函数使用过多内存的结论的? -
对不起,我的意思是编译后的程序大小)EaseFunction 看起来像这样
float Func1(float x) { return (x*x)/(x*x+(1-x)*(1-x)); } float EaseFunction(byte percent,byte type) { if(type==0) return Func1(float(percent)/100); } -
您应该编辑问题,以便其他人更容易找到和理解您的问题。
-
该代码看起来不大。您的目标是哪种机器/微控制器/环境?
-
你试过 gcc 的 -Os 选项吗(看看这里:gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html)?您也可以尝试在编译后剥离您的二进制文件 (sourceware.org/binutils/docs-2.16/binutils/strip.html)。
标签: c memory optimization arduino