Thread: less use of ram

  1. #1
    Registered User
    Join Date
    Dec 2005
    Location
    Denmark
    Posts
    13

    less use of ram

    Hi.

    In my menu system, I use different languages, about 5 different.

    I have stored my text in the rom and I use a pointer to every text line like this.

    Code:
    const char *MenuHeadline[NUM_OF_LANG]= {"Danish","German","English","","",};
    My problem is now, that I use 3 byte of ram of every pointer I use for my text line.
    For this headline I use 3(24bit) x 5 = 15 byte. and I only have 8kb in my microprocessor (I use a lot of text I my menu).

    I like this way because it is simple to use, but is there another way to do something like that, with less use of ram?

    Hope you can help me, and thanks
    Søren Panduro – Denmark

  2. #2
    Unregistered User
    Join Date
    Sep 2005
    Location
    Antarctica
    Posts
    341
    can you load them from an external source? that may take up more ram though.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > "Danish","German","English"
    Option 1 - tokenise the languages into common substrings. Eg.
    "Dan\x80","German","Engl\x80"
    And store a lookup table of common substrings, like
    "\x80ish"
    How many unused characters there are depends on what character sets(s) you support. Guessing from your post, you're looking to support a number of west european languages.

    Option 2 - chain the strings, so you have
    "Danish\0German\0English"
    Use say strlen() to walk down each string to find the one you want.

    Option 3 - use compression - eg. http://www.zlib.net/
    You only need to have the decompressor running on target, and you only need to expand the current language (all your other languages remain compressed, taking up very little space).
    There are plenty of other algorithms, choose one with a really small footprint for the decompression side.

    All the hard work of tokenising, concatenating and compressing can be done using whatever host tools you can find (or write).

  4. #4
    Registered User fischerandom's Avatar
    Join Date
    Aug 2005
    Location
    Stockholm
    Posts
    71
    What processor and compiler are you using? The best technique to use depends on the C compilers implementation of the code you are using because some MCU's have very little registers (some PIC processors only have a single register and issues such as bank switching may affect the code stream in the PIC), so it will affect the total amount of code+data used in the program.
    Bobby Fischer Live Radio Interviews http://home.att.ne.jp/moon/fischer/

  5. #5
    Sr. Software Engineer filker0's Avatar
    Join Date
    Sep 2005
    Location
    West Virginia
    Posts
    235
    An alternative is to define an array of pointers to strings for each language in ROM, and set a RAM pointer at runtime to the appropriate language, then use message indexes off that pointer in your code.
    Code:
    /* ROM data */
    char * messages_English[NUM_MESSAGES] =
    {
        "message 1 in English",
        "message 2 in English",
        "message 3 in English",
        "message 4 in English"
    };
    
    char * messages_German[NUM_MESSAGES] =
    {
        "message 1 in German",
        "message 2 in German",
        "message 3 in German",
        "message 4 in German"
    };
    
    char ** message_sets[NUM_OF_LANG] =
    {
        messages_English,
        messages_German
    }
    Code:
    /* RAM resident pointer */
    char **message_File = message_sets[lang_index];
    You then always reference your strings through message_File, as in
    Code:
    displayMessage(message_File[MSG_INDEX]);
    where displayMessage() is a hypothetical function that displays a message, and MSG_INDEX is the index of the message you wish to display.
    Insert obnoxious but pithy remark here

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. RAM upgrade
    By BobS0327 in forum Tech Board
    Replies: 6
    Last Post: 12-10-2008, 08:14 AM
  2. Ways to save RAM when RAM is very limited
    By suzanne_lim in forum C Programming
    Replies: 22
    Last Post: 02-07-2006, 01:39 AM
  3. Programming and RAM
    By spveer in forum C Programming
    Replies: 3
    Last Post: 06-16-2005, 11:17 AM
  4. RAM how do i know?
    By Boomba in forum Tech Board
    Replies: 5
    Last Post: 06-18-2003, 08:17 PM
  5. pointerz
    By xlordt in forum C Programming
    Replies: 6
    Last Post: 01-11-2002, 08:31 PM