Thread: Segmentation fault

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    28

    Segmentation fault

    I ran into a segmentation fault when I declare big arrays such as

    double array[128][10240];

    this occupies only 10MB of memory (I have 320 MB of RAM). What is the problem? Thanks for help.

    I can use malloc to allocate 10MB of space for this (using pointers), however I doubt it would be in a large block of continuous memory.

  2. #2
    Registered User
    Join Date
    Jun 2003
    Posts
    28
    I have used MS Visual C++ 6.0, GCC, and MPICC to compile. Only worked with small sized arrays.

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by skyglin
    I have used MS Visual C++ 6.0, GCC, and MPICC to compile. Only worked with small sized arrays.
    As Salem asked earlier: Is it a local or global array? Static or automatic? This will determine where it's trying to be allocated: heap or stack.

    My bet is it's local/non-static. Make it a global variable, or a static array.

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

  4. #4
    Registered User
    Join Date
    Jun 2003
    Posts
    28
    sorry, it's local/non-static.

    I have tried global and it worked. Is there any way to make it work as a local array?

    How come global works but not local?

    Thanks a lot!

  5. #5
    _Elixia_
    Guest
    or malloc it. Malloc is guaranteed to return a chunk of contiguous memory of the size you request.

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by _Elixia_
    or malloc it. Malloc is guaranteed to return a chunk of contiguous memory of the size you request.
    Slight correction:

    Malloc is guaranteed to return a chunk of contiguous memory of the size you request. Or, it will fail, returning NULL.

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

  7. #7
    Registered User
    Join Date
    Jun 2003
    Posts
    28

    Thumbs up

    Thank you for your guys' help. This site is really helpful!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Segmentation fault problem
    By odedbobi in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2008, 03:36 AM
  2. Segmentation fault
    By bennyandthejets in forum C++ Programming
    Replies: 7
    Last Post: 09-07-2005, 05:04 PM
  3. Segmentation fault
    By NoUse in forum C Programming
    Replies: 4
    Last Post: 03-26-2005, 03:29 PM
  4. Locating A Segmentation Fault
    By Stack Overflow in forum C Programming
    Replies: 12
    Last Post: 12-14-2004, 01:33 PM
  5. Segmentation fault...
    By alvifarooq in forum C++ Programming
    Replies: 14
    Last Post: 09-26-2004, 12:53 PM