Big 2D array

This is a discussion on Big 2D array within the C++ Programming forums, part of the General Programming Boards category; I asked this question in the C board but I was wondering if this could work in C++. The C ...

  1. #1
    Wanabe Laser Engineer chico1st's Avatar
    Join Date
    Jul 2007
    Posts
    168

    Big 2D array

    I asked this question in the C board but I was wondering if this could work in C++.
    The C board said I might be pooched. (my program is actually in c++ but mostly written in C... it wasnt my choice). Sorry for posting 2 times. I also suppose my declaration would be different, but is this possible to do?
    ************************************************** *

    I need to make a 1x128,000,000 element array (it looks like)

    Code:
    [1]
    [2]
    [3]
    [4]
    ...
    [128000000]
    but i cant seem to declare 128,000,000 elements my C program seems to crash As soon as I try. Not my computer just the c++ program

    Here is the declaring line of code (i dont have code for this array any where else yet.)

    Code:
    int TransposeData[1][128];
    I do get this error when I compile but i ignored it

    Code:
    C:\...cpp(256) : warning C4101: 'TransposeData' : unreferenced local variable
    can i use an array this big?

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    Asking the question more than once is stupid, and a violation of the rules.

    As I said before, if you need that much memory for a simple project, you've probably messed up on the project design.

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I agree with MacGyver on both accounts.

    But to answer the specific question: No there's no real difference between large arrays in C or C++. I also gave some comments in the other thread, and these also apply here.

    Now that's cleared up, maybe some moderator can lock this thread.

    --
    Mats

  4. #4
    Wanabe Laser Engineer chico1st's Avatar
    Join Date
    Jul 2007
    Posts
    168
    sorry
    i didnt know it would be that similar.

    i tried to use malloc it works ok with a 128,000,000x1 array
    but im not sure how to do a 2D array with malloc
    here is the code i used to make a 128000000x1 array (i'm not actually using int that was just for testing)

    Code:
    Data[0] = (U16 *) malloc(( NumberofElements)*sizeof(U16));
    im trying to find malloc for 2D array on google.

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,589
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  2. question about multidimensional arrays
    By richdb in forum C Programming
    Replies: 22
    Last Post: 02-26-2006, 08:51 AM
  3. malloced 2d array passed to qsort
    By jamie85 in forum C Programming
    Replies: 7
    Last Post: 11-25-2005, 12:55 PM
  4. Text file to 2D Array PLEASE HELP!
    By lostboy101 in forum C Programming
    Replies: 0
    Last Post: 03-26-2002, 09:51 AM
  5. 2d Array access by other classes
    By deaths_seraphim in forum C++ Programming
    Replies: 1
    Last Post: 10-02-2001, 08:05 AM

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