huge numbers are not acceptable , why?

A

ArShAm

Hi there
In this code , I need a huge table , but for numbers more than 259025 it
crashes , why?
How to fix that problem?

void main(void)
{
int Sorted[1000000];
Sorted[1] = 1;
}



also i have a table like this :
myTable *table[1000000];
till here is ok , but :
table=&anothertable;
again crashes for more than that number


please help me to fix these problems

Regards
ArShAm
 
A

Ali R.

Try this

int *Sorted = new int[1000000];

//do your stuff
delete [] Sorted;

Ali R.

Hi there
In this code , I need a huge table , but for numbers more than 259025 it
crashes , why?
How to fix that problem?

void main(void)
{
int Sorted[1000000];
Sorted[1] = 1;
}
also i have a table like this :
myTable *table[1000000];
till here is ok , but :
table=&anothertable;
again crashes for more than that number


please help me to fix these problems

Regards
ArShAm
 
P

Peter van Merkerk

In this code , I need a huge table , but for numbers more than 259025
it
crashes , why?
How to fix that problem?

void main(void)
{
int Sorted[1000000];
Sorted[1] = 1;
}

Most likely because you have run out of stack space. The Sorted array
stores its data on the stack, which is often a limited resource. Given
the number 259025 * sizeof(int), my guess is that the stack size on your
platform is 1 MByte. Also note that main() doesn't return void; main()
always returns int.

One way to get around the stack size limitation is to allocate the array
on the heap as Ali R. suggested. But an even better way to do it is to
use std::vector which also stores its data on the heap but doesn't
require explicit resource management:

#include <vector>

int main()
{
std::vector<int> Sorted(1000000);
Sorted[1] = 1;

// No need to delete anything!
return 0;
}
also i have a table like this :
myTable *table[1000000];
till here is ok , but :
table=&anothertable;
again crashes for more than that number


The same problem. The reason that the line myTable *table[1000000]
doesn't crash immediately is that it doesn't generate executable code
with many compilers. However as soon as you start accessing elements it
will access memory that is beyond the stack, hence the crash. Again
using std::vector should fix this problem.
 
A

ArShAm

Thanks Ali jan
The problem is here : ==> Sorted=i;
if you remove this section , program works ;

in my code , the main thing was this :
myClass* table[1000000];//to here , its ok
table->datd=data;//here is problem , that program crashes


Thanks
ArShAm



Ali R. said:
Try this

int *Sorted = new int[1000000];

//do your stuff
delete [] Sorted;

Ali R.

Hi there
In this code , I need a huge table , but for numbers more than 259025 it
crashes , why?
How to fix that problem?

void main(void)
{
int Sorted[1000000];
Sorted[1] = 1;
}
also i have a table like this :
myTable *table[1000000];
till here is ok , but :
table=&anothertable;
again crashes for more than that number


please help me to fix these problems

Regards
ArShAm

 
T

Thomas Matthews

ArShAm said:
Thanks Ali jan
The problem is here : ==> Sorted=i;
if you remove this section , program works ;

in my code , the main thing was this :
myClass* table[1000000];//to here , its ok
table->datd=data;//here is problem , that program crashes


Thanks
ArShAm


1. Don't top-post. Replies are interwoven or appended to the
bottom of a reply, like this one.
2. We need to see your class declaration and the smallest amount
of "compilable" code which demonstrates the issue.
3. Tell us what the expected behavior is and the actual behavior.
4. The possibilities:
4.1. Operator -> is overloaded incorrectly.
4.2. Operator = is overloaded incorrectly.
4.3. The index variable, i, is out of range.
4.4. The index variable, i, is a floating point value.
4.5. The compiler could not find a conversion function for
converting "data" to "datd" (if necessary).
As you can see, there are many possibilities, but we can't
narrow them down until you show some code (see #2 above).

Please read the Welcome.Txt and C++ FAQs below. They will
provide information on how to post as well as other excellent
information.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book
 
A

Ali R.

ArShAm said:
Thanks Ali jan
The problem is here : ==> Sorted=i;
if you remove this section , program works ;

in my code , the main thing was this :
myClass* table[1000000];//to here , its ok
table->datd=data;//here is problem , that program crashes


Well, now you are posting different problem. You are declaring an array of
pointers to your class but you aren't initializing the array with anything.

In this case you would use the vector class

vector<myClass> Table(1000000);

or if you are getting the pointers to the objects from someplace else

vector said:
Thanks
ArShAm



Ali R. said:
Try this

int *Sorted = new int[1000000];

//do your stuff
delete [] Sorted;

Ali R.

Hi there
In this code , I need a huge table , but for numbers more than 259025 it
crashes , why?
How to fix that problem?

void main(void)
{
int Sorted[1000000];
Sorted[1] = 1;
}
also i have a table like this :
myTable *table[1000000];
till here is ok , but :
table=&anothertable;
again crashes for more than that number


please help me to fix these problems

Regards
ArShAm


 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top