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

  • Home
  • SEARCH
  • 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 8208463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:22:40+00:00 2026-06-07T09:22:40+00:00

Using GCC 4.4 (generally the max available for Android and IOS) is there a

  • 0

Using GCC 4.4 (generally the max available for Android and IOS) is there a way to do compile time hashing of strings.

We have a resource manager that maps string keys to resources. While the lookup is fast the hashing and string creation is slow. Something like:

 ResourcesManager::get<Texture>("someKey");

Spends a lot of time allocating the string “someKey” and then hashing it.

I’m wondering if there is a trick I can use to hash it at compile time.

  • 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-06-07T09:22:41+00:00Added an answer on June 7, 2026 at 9:22 am

    You’d have to implement the right hashing algorithm, but this could work using C++11’s constexpr functions:

    #include <iostream>
    
    // Dummy hashing algorithm. Adds the value of every char in the cstring.
    constexpr unsigned compile_time_hash(const char* str) {
        // Modify as you wish
        return (*str == 0) ? 0 : (*str + compile_time_hash(str + 1));
    }   
    
    int main() {
        unsigned some_hash = compile_time_hash("hallou");
        std::cout << some_hash << std::endl;
    }
    

    Then you could have an overload of ResourcesManager::get which takes the result of compile_time_hash(an unsigned, in this case).

    This obviously depends on which hashing algorithm you’re applying. Implementing something like SHA* using constexpr will be pretty painful.

    Note that you require GCC >= 4.6 or clang >= 3.1 in order to use constexpr.

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

Sidebar

Related Questions

I am using gcc on linux to compile C++ code. There are some exceptions
I'm using gcc 4.3.2. I have the following code (simplified): #include <cstdlib> template<int SIZE>
I am using gcc/g++ to compile c/c++ applications - living on OpenSuSe btw. Is
Using gcc on Ubuntu, should there be a (speed) performance difference if compiling the
I've been using gcc's Intel-compatible builtins (like __sync_fetch_and_add ) for quite some time, using
Using gcc 4.6 with -O3, I have timed the following four codes using the
Using GCC 4.2. I have this metatemplate for conditional type: template <bool condition, typename
Using GCC 4.2 to compile project, very slow, from where I can see compiling
I have C/C++ code which is giving a segfault. It is compiled using gcc/g++
Using GCC, how can I remove a symbol from a shared object after I've

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.