arrays

This is a discussion on arrays within the C++ Programming forums, part of the General Programming Boards category; i'm writing a program that stores words in a two dimensional array. my program works fine if i use this ...

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    57

    arrays

    i'm writing a program that stores words in a two dimensional array. my program works fine if i use this array[4000][30], however i want to store a lot of words in this array and if i try and make it bigger......say array[10000][30] then it doesnt work right. any idea of why this might be?

  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Why do you need such a large array anyways? array[10000][30] would take up 300KB of memory.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #3
    Registered User
    Join Date
    Feb 2003
    Posts
    57
    because i'm downloading words from web sights and if its a fairly large websight then it will have a lot of words on it.

  4. #4
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Why don't you just write the words to a file? What are you planning on doing with the words after you retrieve them? We need more info.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  5. #5
    Registered User
    Join Date
    Feb 2003
    Posts
    162
    try it off the heap.

  6. #6
    Registered User
    Join Date
    Feb 2003
    Posts
    57
    what do you mean off the heap

  7. #7
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    Using the heap instead shouldn't make a difference, you'll have the same problem. Use virtual memory.

  8. #8
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    he means you are declaring your array on the stack. A large array like that causes a stack overflow- not a good thing- and so you should use some sort of dynamic memory allocation.
    You will need to use new/delete or new[]/delete[] or malloc()/free().
    Making dynamic 2d arrays has been done many times so if you search the c++ boards you will come up with an example.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Function to read in two arrays
    By ssmokincamaro in forum C Programming
    Replies: 7
    Last Post: 11-12-2008, 07:59 AM
  2. pointers & arrays and realloc!
    By zesty in forum C Programming
    Replies: 14
    Last Post: 01-19-2008, 04:24 PM
  3. Replies: 16
    Last Post: 01-01-2008, 04:07 PM
  4. Need Help With 3 Parallel Arrays Selction Sort
    By slickwilly440 in forum C++ Programming
    Replies: 4
    Last Post: 11-19-2005, 10:47 PM
  5. Crazy memory problem with arrays
    By fusikon in forum C++ Programming
    Replies: 9
    Last Post: 01-15-2003, 09:24 PM

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