[C++] Error[Lp001] running out of memory when I shouldn't

Status
Not open for further replies.

SimplyEvert

Newbie level 1
Joined
Mar 24, 2015
Messages
0
Helped
0
Reputation
0
Reaction score
0
Trophy points
0
Activity points
23
Hi, Im currently working on a project which uses different language settings. To solve this a table is used to store all the texts in different languages that are used in the program. So whenever a text is about to be written on the screen this table is called and depending on what the current language setting is a text string is returned. I recently joined this project and I noticed that the way of storing this wasn't very optimized and for every new language that was added the time it would take to look up the correct string would increase. I therefore came up with a (in my mind) better solution. However, when I tried to implement it I ran into the problem of getting an error that too much memory is used and I don't understand why. I am using IAR enbedded workbench.

The original solution in pseudo/c++ code:


Code C++ - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
typedef struct
{
    enum textId;
    enum language;
    string textString;
} Text;
 
static const Text s_TextMap[] = 
{
     { TextId::RESTORE_DATA_Q                ,Language::ENGLISH        ,"Restore Data?"                          },
     { TextId::RESTORE_DATA_Q                ,Language::SWEDISH        ,"Återställa data?"                       },
     { TextId::RESTORE_DATA_Q                ,Language::GERMAN         ,"Wiederherstellen von Daten?"            },
     { TextId::CHANGE_LANGUAGE               ,Language::ENGLISH        ,"Change Language"                        },
     { TextId::CHANGE_LANGUAGE               ,Language::SWEDISH        ,"Välj språk"                             },
     { TextId::CHANGE_LANGUAGE               ,Language::GERMAN         ,"Sprache wählen"                         },
};



My solution in pseudo/c++ code:


Code C++ - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
typedef struct
{
    const char* pEngText;
    const char* pSweText;
    const char* pGerText;
} Texts;
 
static Texts addTexts(const char* pEngText, const char* pSweText, const char* pGerText)
{
    Texts t;
    t.pEngText = pEngText;
    t.pSweText = pSweText;
    t.pGerText = pGerText;
    return t;
}
 
typedef struct
{
    TextId::e textId;
    Texts texts;
} Text;
 
static const TextTest s_TextMapTest[] =
{
     {TextId::RESTORE_DATA_Q,        addTexts("Restore Data?","Återställa data?","Wiederherstellen von Daten?")},
     {TextId::CHANGE_LANGUAGE,        addTexts("Change Language","Välj språk","Sprache wählen")},
};



My solution is obviously faster to lookup in the average case and based on my calculations it should also use less memory. When the full tables are used I've calculated that the original solution requires 7656 bytes and that my solution requires 4224 bytes. However, when I try to compile the code I get linking errors saying:

 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…