By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,507 Members | 1,758 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,507 IT Pros & Developers. It's quick & easy.

How to find the Maximum size of static data?

P: n/a
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

Nov 22 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Divick wrote:
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

Nov 22 '05 #2

P: n/a
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

Nov 22 '05 #3

P: n/a
Opps ..I posted the wrong code....the actual code is

#define MAX_SIZE 1048576
//#define MAX_SIZE 1000000

int main()
{
int arrayOfAddresses[MAX_SIZE];

}

Nov 22 '05 #4

P: n/a
Divick wrote:
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
Nov 22 '05 #5

P: n/a
Divick wrote:
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.
Nov 22 '05 #6

P: n/a
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

Nov 22 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.