PDA

View Full Version : Saving memory with improved add_ppm_strings.rx



nuukiaworld
04-02-2006, 03:43 PM
I noticed that those common PPM strings that are not NokiX built-in strings are added to the PPM every time when add_ppm_strings is called, even if exactly the same texts already reside in the PPM! :-o

I made quick and dirty modifications to add_ppm_strings.rx: This version checks all previously added texts before adding a text and if it can find a text that matches competely* to the new one, the new text will not be added. – Only a new nokstr_t variable is created to point to the "old" text already present in the PPM.
* All those languages that are present in the PPM must contain the same string. Languages missing from either text are not compared. If a match is found but the "new" text contain languages that do not exist in the "old" text, they are added to the "old" text.This modification saved more than ½ kB of flash space on my phone (which has only two languages; I had 6 bytes free, now I have over 500 bytes free! :grin: ). The amount of saved flash space will be bigger if you have many languages in your PPM. The change did not create any problems with any script I use! :P

For example, several games have texts "Clear top score" and "Top score cleared!". After this change, these texts are included in the PPM only once, even if each game tries to add them there as "LOCAL" or "VAR" texts. (No changes are required to the actual scripts or _ppm files!)

BTW: add_ppm_strings may be optimized even further to use a single nokstr_t variable for all occurences of the same text. However, then the _ppm files should be able to tell if the script expects the nokstr_t variables to be in successive memory locations (e.g. when they form an array), i.e. there should be a flag that forces the creation of a new nokstr_t variable even if an old one exists... Edit: forget this, it makes everything more complicated and would save only a few additional bytes...

mestrini
04-02-2006, 08:40 PM
nice job :eek:

clearly a programmer way of thinking ;)

nuukiaworld
04-02-2006, 08:57 PM
clearly a programmer way of thinkingMay be "a programmer way of thinking" but not "a programmer way of writing" REXX code :roll:. It's really a quick and dirty change; I wanted to touch the original code as little as possible.

I dare to say that I can write efficient and clean C code (if I want) but writing REXX is a nightmare for me... :sad:

yak
25-02-2006, 08:57 PM
I've reimplmented this feature in official script. Additionaly, the string pointers are also reused so even the 0x04xxxx are not created twice.

Your Rexx code is not that bad, Rexx is Basic alike language so programs written in it are always a bit dirty :).

I've used the feature of NokiX 1.30 (environment variables listing, '*') instead of ppman macro to list the languages.

Thanks for the tip and idea.
[Yak]

--ADDED --

I had to rework it from scratch. First implmentation was too dirty even for Rexx :). Now it's quite nice I think and problems of first implementation disappeared.

nuukiaworld
26-02-2006, 06:15 PM
Additionaly, the string pointers are also reused so even the 0x04xxxx are not created twice.So a script cannot build (anymore) an array of string pointers by putting the string sequentially in the ppm file? Ok, it has been undocumented feature so far but may be there should be an explicit way to do that...

yak
27-02-2006, 12:31 AM
Before I introduces the LOCAL parameter when I published the new SDK, the strings were inserted only if env pool var specified by VAR wasn't set. It it was, string was skipped so you couldn't expect that it will always form an array.

Anyway, if the docs doesn't say it forms an array then expecting it menas bad programming and that's not my problem. Those few affected may be some scripts using weekdays and that will form an array.

nuukiaworld
16-10-2010, 04:23 PM
I wake up this over 4? year-old thread by adding a clearly missing optimization in the add_ppm_strings.rx. I cannot understand why I forgot it that time! :confused:

Namely, the current implementation (v. 2.53) of add_ppm_strings.rx scans only the strings added by itself for duplicates. Why not to scan also the built-in strings of the phone? Many strings used by NokiX scripts are same as a built-in string, so remarkable flash space savings can be achieved by not adding a second copy of such string.

My new add_ppm_strings.rx 2.6 starts by loading the built-in PPM strings into the pool for later comparison. Custom strings are not added if same string can be found already in the PPM. Only one nokstr_t is created for such string.

Download my version from www.panuworld.net/nuukiaworld/download/nokix/improved (http://www.panuworld.net/nuukiaworld/download/nokix/improved/). Note that you must copy the add_ppm_strings.rx from the package to your main scripts folder, otherwise other scripts cannot find it.

On my two-language phone this change freed ~500 bytes of flash space. On phones with larger number of languages, more savings can be expected.

nuukiaworld
16-10-2010, 08:38 PM
Fixed a typo related to \uXXXX parsing a few minutes ago.

There might be more such small typos, as I have not tested it completely, just with those scripts I use for my phone.