'Efficiency of gettext : in-memory translation
I have an embedded system with Flash and a very low end CPU and less RAM. I wanted to know how efficient is the gettext language translation using .MO file.
For doing the locale language string fetch, do every time gettext read MO file from flash OR, the complete MO binary file is first loaded into RAM, and do the locale string fetch from there ?
If the MO file (It will be large ~1Mb since there are a lot of strings) is always loaded into RAM, it will eatup my RAM.
Solution 1:[1]
gettext is typically used with a hash table:
when the user selects a language, the content of a
.mofile is processed to find offsets of every translation. Those offsets are stored in a hash table.when a translated string is to be displayed, the hash of the corresponding English string is calculated, and the offset of the translated string is found using that hash.
If the fhash memory in your embedded system is mapped to the address space, the English strings and the translations can be stored in the flash. Only the hash table will need to be in RAM. You'll need to reserve the size of one hash and one pointer per translated string. If you use CRC32 as a hash and 4-byte pointers, you'll need 8kB of RAM for 1024 translated strings.
If you don't have flash memory mapped to the address space, you'll have to either load a complete .mo file in the RAM when a language is selected, or call a flash IO routine every time you want to display a string.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Dmitry Grigoryev |
