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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:34:30+00:00 2026-05-27T05:34:30+00:00

I have a program where I’m a table of a decently large block of

  • 0

I have a program where I’m a table of a decently large block of memory, it’s a structure with two integers (they would have to be at least 4 bytes a piece to hold up to 1,000,000,000). The structure currently has a little more than 500 entries into it. So we’re talking about 4k. 4k of stack space doesn’t seem like a lot, but it does seem wasteful for a function that may only be called once in a blue moon. (Assume we’ll call it once over the life time of a program, so if it’s slightly slow to allocate, it’s ok as that space is more value over the allocation time).

The code is just a simple look up of values, the code to generate it is quite heavy, and we only are looking for specific values anyways. I’ve the code already, and the look up is by far faster, so there’s no question that I want to go down this route. I could add in a file load to get the data out of a file, but to me that seems overkill at least at this point.

Now there’s two ways I can think of allocating it. Making it a global variable, and making it a local variable. Obviously, local is the way to go as it’s only this function that needs the table. However what I’m looking for is if there’s any keywords I can use, or any way of loading that variable (currently it’s just a array of these pairs) that will be the most beneficial.

My best case is to make it attempt to be in memory only for the scope of the function, and then to allow that memory to be returned to the system. in as efficient a way as possible. Is there a step beyond making the data local that I should take?

  • 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-27T05:34:30+00:00Added an answer on May 27, 2026 at 5:34 am

    Is there a step beyond making the data local that I should take?

    Nothing more. It should look like this:

    void proc() {
      t_thing things[500]; // << you could use std::array here too
    }
    

    It’s doubtful that it is ‘slow’ for your needs. If you want to improve this, specifying the alignment could help.

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

Sidebar

Related Questions

I have program that is used by 4000 users to search a large database
I have program that uses shared memory and protects it with semaphore to communicate
I have a program that runs a large number of regular expressions (10+) on
I have a program that classifies text and would like to make it interactive
i would like to have program a timer that will count the seconds during
I have program with two files; main.py that has my main logic and class.py
My program have evaluate hundreds of millions of records. So the question of memory
I have two programs, Program A is like this, int main(int argc, char** argv)
I have program that has a variable that should never change. However, somehow, it
I have program, that must interact with a console program before my program can

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.