Author Topic: Heap size  (Read 14496 times)

lev9596

  • Guest
Heap size
« on: September 18, 2006, 07:32:18 pm »
Yeah, I was wondering if there was a way to change the heap size in CodeBlocks, i have searched all through the program and have not been able to find it....Also i would like to know if there is a default size for the heap and what it is.  If i could get help with this it would be greatly appreciated.  Thanks


Jedon

Offline rcoll

  • Almost regular
  • **
  • Posts: 150
Re: Heap size
« Reply #1 on: September 18, 2006, 07:46:08 pm »
Are you talking about the actual heap used by C::B, or the heap that your program (I assume you are compiling a program) will be using?

If for your program, that would probably be a command-line option for whatever compiler you are using.

-- ron --

lev9596

  • Guest
Re: Heap size
« Reply #2 on: September 18, 2006, 07:57:48 pm »
I am talking about the Heap of the program i am compiling, becuase every time i run a program in CodeBlocks that has a 2 dimensional array, i get a windows error the needs to be debugged or sent to microsoft.  I also get this same problem in Visual Studio 6...and i just wondered if there was a way to change the heap size like the is in visual studio. Also what would be the syntax for a command-line option??
« Last Edit: September 18, 2006, 08:00:49 pm by lev9596 »

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Heap size
« Reply #3 on: September 18, 2006, 08:05:09 pm »
When using GCC/MinGW, add the --heap switch to the linker's options. This switch has two variations:
1. --heap reserve
2. --heap reserve,commit

Consult man ld for more information. A similar option probably exists for every compiler (including the Microsoft one). If nothing helps, you can edit the PE header using a simple hex editor, or more comfortably using a tool like PEResourceExplorer. The stack size can be found in the optional header at location 0x4a.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

lev9596

  • Guest
Re: Heap size
« Reply #4 on: September 18, 2006, 08:31:49 pm »
Still having problems getting this to work.  I am a relatively new user to this program and programming in C++.  I feel really dumb...has anyone else had a problem with this b4 or is it just me??

mdelfede

  • Guest
Re: Heap size
« Reply #5 on: September 18, 2006, 09:04:34 pm »
Still having problems getting this to work.  I am a relatively new user to this program and programming in C++.  I feel really dumb...has anyone else had a problem with this b4 or is it just me??

I think that's more a general programming question than a C::B one.
BTW, I think you're allocating a very (too ?) big static array. Maybe looking at your code snippet would help....
Anyway, that's not a good programming practice to allocate a similar array; much better work with dynamic data, allocating just what you need.

Ciao

Max

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Heap size
« Reply #6 on: September 18, 2006, 09:08:19 pm »
Right, but since he is addressing a 2D array, it is not quite so simple, he'll have to use an array of pointers to dynamically allocated memory or something (or calculate the row offset by hand).

I am not sure if that's the easiest thing for a beginner to do...
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline rcoll

  • Almost regular
  • **
  • Posts: 150
Re: Heap size
« Reply #7 on: September 18, 2006, 09:41:34 pm »
Right, but since he is addressing a 2D array, it is not quite so simple, he'll have to use an array of pointers to dynamically allocated memory or something (or calculate the row offset by hand).

I am not sure if that's the easiest thing for a beginner to do...

It is not the easiest thing for a beginner, but it is still standard practice.  Like the rest of us that have learned C, he'll just have to jump in and take the time to figure it out.

Jedon -- how big is this array we're talking about?  If it is really huge, and the code is complicated, we'll move this to a regular programming forum and help you through it.

-- ron --

mdelfede

  • Guest
Re: Heap size
« Reply #8 on: September 19, 2006, 06:02:06 am »
Right, but since he is addressing a 2D array, it is not quite so simple, he'll have to use an array of pointers to dynamically allocated memory or something (or calculate the row offset by hand).

I am not sure if that's the easiest thing for a beginner to do...

Not the easiest, but the only 'good' way. On my 'first' programming days I made some structural analysis software, beginning with staticalli allocated matrices, and it was a nightmare :-)
Then, having only C and not C++, I resorted to an 1-dimension dynamic array, simulating a 2 dimension array; the index calculation is quite simple.
The simplest (and more reliable way) now is to write some C++ array class, or to get a ready to use one somewhere.
It would also be a good programming practice for a 'not-absolute-beginner'.

Ciao

Max

lev9596

  • Guest
Re: Heap size
« Reply #9 on: September 20, 2006, 07:59:23 pm »
Actually the array i need to create needs to store the number of permutations 1 through 9 contains.  so there are a 9 factorial possibilities i need to store.  Maybe im just going about it wrong. but this is my code so far.

#include <algorithm>
#include <iostream>



using namespace std;

int main() {
    int numArray[] = {1,2,3,4,5,6,7,8,9};
    int *mainArray = new int[362880*9];
    int a = 1;

    for(int i = 0; i < 9; i++){
        mainArray[0*i] = numArray;
    }
    while(next_permutation(numArray, numArray+9)) {
        for(int i = 0; i < 9; i++) {
            mainArray[a*i] = numArray;
            a++;
        }
        }
    for(int i = 0; i < 9; i++){
    cout << "First " << mainArray[0*i] << endl;
    cout << "Ten Thousandth: " << mainArray[10000*i] << endl;
    cout << "Last " << mainArray[362880*i] << endl;
    }
    delete mainArray;
}

This code is what is giving me crashing problems... and i have no clue why.

Offline Frank3000

  • Multiple posting newcomer
  • *
  • Posts: 17
Re: Heap size
« Reply #10 on: September 20, 2006, 09:19:51 pm »
    while(next_permutation(numArray, numArray+9)) {

Hi,
the pointer to the last element of numArray is numArray + 8 !
Greetings,
Frank
Klingon multitasking systems do not support 'time-sharing'. When a Klingon program wants to run,
it challenges the scheduler in hand-to-hand combat and owns the machine.