Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5848729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:54:01+00:00 2026-05-22T12:54:01+00:00

Alright so I have recently made the decision to put every string in my

  • 0

Alright so I have recently made the decision to put every string in my application into a STRINGTABLE, so I can easily translate to different languages.
I know how to use the LoadString() api, but this involves me having a different variable for every string I want to load, and if my application has 100 strings, thats alot of variables. Is this the best way to do this? Or should i create a global variable thats used as a buffer to load the strings as needed? Also since there’s no way of knowing how big my string is should I just create a big enough buffer to hold any string i could possible have, or is there a better method of doing this?

Also is loading the strings as needed bad for performance? Is there any way i can preload them?

RE: Okay i’ve tried creating a buffer 256 bytes in size and loading the strings into that as needed, though i ran into a little problem…

Here’s my code thats displaying an error message, the error is “Error allocating memory!”

LoadString(g_hInst, IDS_ERROR_MEMORY, szBuffer, sizeof(szBuffer)/sizeof(TCHAR));
MessageBox(NULL, szBuffer, TEXT("Error"), MB_OK | MB_ICONERROR);
ExitProcess(1);

And I have my buffer as a global variable: TCHAR szBuffer[256];

This works but, id like to also store the “Error” text into the string table and load that when I want to display the error, problem is that would require me to have 2 global variables to load the strings, and there are some places where i need to load even more then that at a time.

Is there a better solution then having multiple global variables?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T12:54:02+00:00Added an answer on May 22, 2026 at 12:54 pm

    You can certainly preload them if you want. You’d just need to create an array of string pointers and load each string into that array. Or you could use a hash map or something similar.

    Bad for performance? It depends. If you’re displaying those strings as prompts in a user interface, I don’t see how loading each string as it’s needed is going to be a performance problem. The operating system is going to do some intelligent caching anyway, so it’s not like you’ll be hitting the disk for every string that you need to display. On the other hand, if you’re going to be working with those strings in a tight loop, then it’s probably best to preload them into memory so you don’t have to call LoadString all the time.

    As far as buffers go, I always allocated a buffer that was as large as the largest string I expected to have in my resource file. Considering that user interface strings are typically very small, a 256 byte buffer was more than sufficient. Anything larger than that, I’d either pre-load into memory at startup so I could keep it around, or I wrote a separate method that would allocate a string at load time rather than keeping a buffer around.

    Additional info:

    Rather than defining global variables for your strings, consider writing a function that loads a resource string, makes a copy of it, and returns that copy. That is:

    char * LoadStringFromResource(uint id)
    {
        // szBuffer is a globally pre-defined buffer of some maximum length
        LoadString(ghInst, id, szBuffer, bufferSize);
        // yes, I know that strdup has problems. But you get the idea.
        return strdup(szBuffer);
    }
    

    Your code, then becomes:

    char* errMem = LoadStringFromResource(IDS_ERROR_MEMORY);
    char* errText = LoadStringFromResource(IDS_ERROR_TEXT);
    MessageBox(NULL, errMem, errText, MB_OK | MB_ICONERROR);
    free(errMem);
    free(errText);
    

    The above is C code, but you can easily convert to C++. In particular, you probably want to to modify the wrapper function so that it returns a C++ string–something that will be automatically deallocated when it goes out of scope (using smart pointers or whatever the modern equivalent is).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Alright, I'm trying to read a comma delimited file and then put that into
I recently started programming my first Cocoa app. I have ran into a problem
Alright so I have this C++ image capturing class. I was wondering if I
Alright, currently I have my SWF hitting a php file that will go and
Alright, I have been doing the following (variable names have been changed): FileInputStream fis
Alright. So I have a very large amount of binary data (let's say, 10GB)
Alright. I have a query that looks like this: SELECT SUM(`order_items`.`quantity`) as `count`, `menu_items`.`name`
Alright, so I have a query that looks like this: SELECT `orders`.*, GROUP_CONCAT( CONCAT(
Alright...I've given the site a fair search and have read over many posts about
Is it alright to expect that the user using the back end will have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.