简体   繁体   English

在Action Script和php中引用代码以优化运行时内存使用率

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

I used to write programs in the android sdk for google phone. 我曾经在Google android的android sdk中编写程序。 One of the android developers guide that I read says that it is more efficient to declare a const 我读过的一份Android开发人员指南说,声明const效率更高

public static const NO:String = "no"; 

var1 == NO;
var2 = NO;

than to do this 而不是这样做

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

For Java, when you 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. 对于Java,每次您写入“ no”时,都会创建一个新变量,并在其中存储值“ no”,因此声明该常量的内存效率更高。 I am wondering if that is the case for action script and php as well? 我想知道动作脚本和php是否也是如此? I am maintaining action script and php programs at work and saw a lot of strings declaration like the "no" above being used. 我正在维护动作脚本和php程序,并且看到许多字符串声明,例如上面使用的“ no”。

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. ActionScript使用一个字符串池(包含在编译时发现的每个常量恰好一次),据我所知,这些字符串实际上是同一对象。 If not, they do all point at the same character sequence. 如果不是,它们都指向相同的字符序列。 AS3 can do this, since strings are immutable. 由于字符串是不可变的,因此AS3可以做到这一点。

Please note however access of static members however is the slowest way to access values in ActionScript 3. 但是请注意,访问静态成员是访问ActionScript 3中值的最慢方法。

I don't know about PHP though. 我不了解PHP。

greetz 格里茨
back2dos back2dos

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM