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 8379089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:05:10+00:00 2026-06-09T16:05:10+00:00

I have implemented an algorithm for which there is a strong use-case to know

  • 0

I have implemented an algorithm for which there is a strong use-case to know as soon as possible the maximum problem sizes that will be computed during the whole execution of the library so that the required memory (matrices, vectors etc) can be efficiently pre-allocated. “As soon as possible” defined as even earlier or no later than when the C++ static initialization triggers e.g.

  /**
   * Example of what I would like to accomplish but of course this 
   * System#getProperty is the Java way
   */
  class texample {
      static const int MAX_M_N;
  }

  const int texample::MAX_M_N = System.getProperty("maxMN");  // possible? how?

I could of course do this using dynamic initialization and allocation instead but it will be a lot simpler if these input argument properties are ‘seen’ during static initialization time. The reason being that the wrapper object instances statically-initialized/allocated will get destructed also by the static destruction process and I won’t have to worry about it e.g. handling exceptions and manually freeing/deleting the instances.

UPDATE: and one more thing 🙂 I’d like to have this without having to recompile. I can of course use a macro (I’m using CMake) so it would be very easy to change the macro in the CMakeList.txt file and re-compile but I’d prefer to have the sizes specified dynamically at runtime.

  • 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-09T16:05:12+00:00Added an answer on June 9, 2026 at 4:05 pm

    If reading from the environment is acceptable, you could try this:

    #include <cstdlib>
    
    int readme(char const * envname)
    {
        char * e, * env = std::getenv(envname);
    
        if (!env)
        {
            std::cerr << "Environment '" << envname << "' missing, aborting.\n";
            std::exit(0);
        }
    
        int res = std::strtol(env, &e, 0);
    
        if (*e != 0)
        {
            std::cerr << "Environment '" << envname << "' unparsable (contains '" << env << '"), aborting.\n";
            std::exit(0);
        }
    
        return res;
    }
    
    int const texample::MAX_M_N = readme("maxMN");  // #1
    

    Note that line “#1” is executed during the dynamic initialization phase of your program, which is the first time user code is executed, and it completes before main is called.

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

Sidebar

Related Questions

I know that Floyd–Steinberg dithering algorithm can't be implemented with pixel shader, because that
I have implemented a graph traversal algorithm which finds a path between two nodes
I have implemented an evolutionary algorithm in C# which kind of works but I
I have implemented an algorithm for floating point decimal to rational fraction approximation (example:
I have implemented the A* algorithm in AS3 and it works great except for
This is regarding AES algorithm. Suppose i have implemented a AES algorithm and encrypt
I am trying to implement an efficient algorithm for nearest-neighbour search problem. I have
I have this algorithm that I want to implement on VB6. Sub Main() dim
i have a string in C which i got from some algorithm. it has
I have implemented a simple parallel merge sort algorithm in Java. This cuts the

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.