How to find the Maximum size of static data?

D

Divick

Hi all,
how can I figure out what is the maximum size of data that can
be allocated in static area on a particular architecture. I am using
g++ on 64 bit Intel architecture and when I create a static array of
size 2^20, then my program seg-faults.

Thanks,
Divick
 
B

BigBrian

Divick said:
Hi all,
how can I figure out what is the maximum size of data that can
be allocated in static area on a particular architecture.

Ask somebody who knows about your specific platform.
when I create a static array of
size 2^20, then my program seg-faults.

If thing this is because you are having C++ language problem, post your
code so everybody can see exactly what you're trying to do.

-Brian
 
D

Divick

What if I am doing the same thing on say Windows XP 32 bit OS?
Essentially what is the way to know the maximum size of static array on
any platform.

My code is pretty simple as shown below. If I change the size to
1000000 then I don't get a crah while if I simply compile and run this
on 64 bit linux then I get a crash.

#define MAX_SIZE 1048576
//#define MAX_SIZE 1000000

int main()
{
int ** arrayOfAddresses = new int *[MAX_SIZE];
}

Thanks,
Divick
 
D

Divick

Opps ..I posted the wrong code....the actual code is

#define MAX_SIZE 1048576
//#define MAX_SIZE 1000000

int main()
{
int arrayOfAddresses[MAX_SIZE];

}
 
J

John Harrison

Divick said:
Opps ..I posted the wrong code....the actual code is

#define MAX_SIZE 1048576
//#define MAX_SIZE 1000000

int main()
{
int arrayOfAddresses[MAX_SIZE];

}

There's no answer to your question. Every compiler and/or platform is
going to be different. Code that needs to create arrays this big is
flawed code. Why do you think you need an array this big?

john
 
R

red floyd

Divick said:
Opps ..I posted the wrong code....the actual code is

#define MAX_SIZE 1048576
//#define MAX_SIZE 1000000

int main()
{
int arrayOfAddresses[MAX_SIZE];

}

That's not static data. That's allocated on the stack. You're
allocating 4MiB on the stack. Your system can't handle that, and
crapped out with a stack overflow.
 
D

Divick

Yeah you are right , but I just had this query. I just wrote a small
test code and tried to allocate the data on the stack and later
realized and modified to be allocated on heap. Still my question
remains unsolved. Sometimes, you want to create some data on the stack,
rather than on the heap , and that led to my question.

anyways thanks,
divick
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top