开发者

Referactoring code in Action Script and php to optimize runtime memory usage

开发者 https://www.devze.com 2023-01-08 21:30 出处:网络
I used to write programs in the android sdk for google phone. One of the android developers guide that I read says that it is more efficient to declare a const

I used to write programs in the android sdk for google phone. One of the android developers guide that I read says that it is more efficient to declare a const

public static const NO:String = "no"; 

var1 == NO;
var2 = NO;

than to do this

var1=="no";     
var2="no";

For Java, when y开发者_高级运维ou write "no" each time, a new variable is created with the value "no" stored in it so it is more memory efficient to declare the constant. I am wondering if that is the case for action script and php as well? I am maintaining action script and php programs at work and saw a lot of strings declaration like the "no" above being used.

I am wondering if it will be worth my time to refactor these code when i have to fix the programs. I plan to leave the programs that I do not have to fix as is. Any advice or insights would be great.


ActionScript uses a string pool (containing every constant found at compile time exactly once) and to my knowledge, the strings are actually the very same object. If not, they do all point at the same character sequence. AS3 can do this, since strings are immutable.

Please note however access of static members however is the slowest way to access values in ActionScript 3.

I don't know about PHP though.

greetz
back2dos

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号