Thread: Gcc array size limit? Can't make arraysbigger than 10MB

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    25

    Gcc array size limit? Can't make arraysbigger than 10MB

    Hi,
    I've got gcc running on a Daul Xeon (1Gb Ram ) server. Problem is I can't seem to have arrays bigger than 10 MB - as in eg:
    char temp[9000000];

    is allowed, but nothing bigger - otherwise I get a segmentation fault. But I need to open files up to 20 - 30 MB in size (email inboxes) to scan them for attachments - and remove the attachment - primitive Anti-virus program I'm writing.

    How do I get c programs to allow much bigger arrays?

    thanks.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Well you should be using malloc to allocate the space you need on a per attachment basis, rather than setting some large upper bound.

    As for the other problem, is this a global array or a local array?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    char *temp = malloc( 1000000000 );
    if( temp == NULL )
    {
        printf("Malloc failure.\n");
        exit(0);
    }
    Be sure to free what you malloc.
    [edit]
    Curses, foiled again!
    [/edit]

    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    Registered User
    Join Date
    Nov 2001
    Posts
    25
    Many thanks!

  5. #5
    Obsessed with C chrismiceli's Avatar
    Join Date
    Jan 2003
    Posts
    501
    just so you know, most modern operating system limit the amount of memory one process user can own, unless of course you are root (or administrator).
    Help populate a c/c++ help irc channel
    server: irc://irc.efnet.net
    channel: #c

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Fixing my program
    By Mcwaffle in forum C Programming
    Replies: 5
    Last Post: 11-05-2008, 03:55 AM
  2. Adventures in labyrinth generation.
    By guesst in forum Game Programming
    Replies: 8
    Last Post: 10-12-2008, 01:30 PM
  3. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  4. templates, unresolved external error
    By silk.odyssey in forum C++ Programming
    Replies: 9
    Last Post: 06-09-2004, 04:39 PM
  5. Hi, could someone help me with arrays?
    By goodn in forum C Programming
    Replies: 20
    Last Post: 10-18-2001, 09:48 AM