Note that there are some explanatory texts on larger screens.

plurals
  1. POBest way to allocate large local memory in a C++ function
    primarykey
    data
    text
    <p>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).</p> <p>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. </p> <p>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. </p> <p>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? </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload