How to find the Maximum size of static data?

Discussion in 'C++' started by Divick, Nov 16, 2005.

  1. Divick

    Divick Guest

    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
     
    Divick, Nov 16, 2005
    #1
    1. Advertising

  2. Divick

    BigBrian Guest

    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
     
    BigBrian, Nov 16, 2005
    #2
    1. Advertising

  3. Divick

    Divick Guest

    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
     
    Divick, Nov 16, 2005
    #3
  4. Divick

    Divick Guest

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

    #define MAX_SIZE 1048576
    //#define MAX_SIZE 1000000

    int main()
    {
    int arrayOfAddresses[MAX_SIZE];

    }
     
    Divick, Nov 16, 2005
    #4
  5. 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
     
    John Harrison, Nov 16, 2005
    #5
  6. Divick

    red floyd Guest

    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.
     
    red floyd, Nov 16, 2005
    #6
  7. Divick

    Divick Guest

    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
     
    Divick, Nov 18, 2005
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bei
    Replies:
    4
    Views:
    50,302
    =?Utf-8?B?QXZuZWVzaA==?=
    Feb 2, 2004
  2. harry
    Replies:
    11
    Views:
    954
    Roedy Green
    Feb 1, 2006
  3. Jason Cavett

    Preferred Size, Minimum Size, Size

    Jason Cavett, May 23, 2008, in forum: Java
    Replies:
    5
    Views:
    12,586
    Michael Jung
    May 25, 2008
  4. Maximum size of POST data?

    , Sep 28, 2006, in forum: ASP General
    Replies:
    1
    Views:
    270
    Tim Slattery
    Sep 28, 2006
  5. phanhuyich
    Replies:
    4
    Views:
    278
Loading...

Share This Page