Problem declaring large arrays

This is a discussion on Problem declaring large arrays within the C Programming forums, part of the General Programming Boards category; Hi, I declare Code: float found[100000][2]; // Stores found.txt float actual[10000][2]; // Stores actual.txt float mov[1000000][3]; // Stores moving.txt int ...

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    7

    Problem declaring large arrays

    Hi,

    I declare

    Code:
    	float found[100000][2];	// Stores found.txt
    	float actual[10000][2];	// Stores actual.txt
    	float mov[1000000][3];		// Stores moving.txt
    	int mapCount[100];		// Stores mapCount.txt
    which i plan to store a lot of numbers from text files and the program always crashes.

    I've narrowed it down the the large declaration because program works fine with smaller arrays.

    I would have thought the computer would have enough memory to be able to do this? Can anyone shed any light on why this can't be done or some alternatives? (I'm already thinking I'm going to have to read data in iteratively but it would be nice to have it all there all at once.

    Thanks

    Matt.

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Matt, check your compiler help. It should give you info on if, how, and how much, may be possible.

    I agree with you that you'll probably have to work with this data in "chunks", smaller than the BIG arrays you were hoping for. And don't forget what your OS can do for you, as well. I was amazed to discover that Windows2000 has special resources available for system sorting - and it leaves my best Quicksort, in the dust for that reason. (and has no such limitations on size like I would have, since it will automatically can use disk drive space as a stand-in for RAM.

    Very sweet.

    Adak

  3. #3
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,066
    You're looking at over 12mb of static memory there if you assume a 32-bit float, so I wouldn't be surprised if you're getting a stack overflow. With that much data, I'd suspect you won't need to access it all at once so your easiest bet would be just to write what you don't immediately need to some sort of swap file and put it into memory dynamically when you need it and delete that memory when you don't.

    As Adak said, your OS might use it's own swap file for your program, but it's not likely to do that if it's all static memory. Try allocating the memory dynamically.
    Last edited by SlyMaelstrom; 09-27-2006 at 08:58 PM.
    Sent from my iPadŽ

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    They're probably using Turbo C++ 3 anyway.


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

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,422
    Assuming that you actually have a 32-bit compiler, and these are local variables in say main, then

    Code:
    static float found[100000][2];
    should get you out of the immediate hole.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  6. #6
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    Why in the world do you need an array that size? It would take eons to fill it up regardless of the algo employed.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Large 2D Array's Problem
    By kas2002 in forum C Programming
    Replies: 4
    Last Post: 05-25-2009, 12:42 PM
  2. Problem with arrays structures sorting.
    By pitifulworm in forum C Programming
    Replies: 42
    Last Post: 02-09-2009, 11:31 AM
  3. arrays problem
    By swapnil_sandy in forum C Programming
    Replies: 3
    Last Post: 11-30-2005, 03:14 PM
  4. Problem with chars and char arrays
    By Zagaberoo in forum C++ Programming
    Replies: 3
    Last Post: 09-27-2003, 08:47 AM
  5. Large Arrays
    By xurumin in forum C++ Programming
    Replies: 7
    Last Post: 08-26-2003, 05:17 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21