Thread: The deal with using 4d arrays :D

  1. #1
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968

    What not to do with arrays :)

    Well I just learned something in the past week, when you have a 4d array, such as

    s[3].[3][14][28]

    and try to loop it as such

    Code:
    for(a; a<3; a++)
    {
    for(b; b<3; b++)
    {
    for(c; c<14; c++)
    {
    for(d; d<28; d++)
    {
    s[a].[b][c][d].sold = false
    }
    }
    }
    }
    Hehe...... yeah, right there is about 10,000 mathematical operations...

    Note to all who may be tempted, don't do this
    Last edited by Shamino; 11-04-2005 at 12:13 AM.

  2. #2
    vae victus! skorman00's Avatar
    Join Date
    Nov 2003
    Posts
    594
    To be exact

    3528 assignments with the array.
    3666 ++ operations.
    Last edited by skorman00; 11-03-2005 at 10:05 PM.

  3. #3
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968
    considering it takes

    column*row+1....... to move through a 2 dimensional matrix.. a 4d one has even more

    multiply it by about 3-5 again
    Last edited by Shamino; 11-03-2005 at 10:06 PM.

  4. #4
    vae victus! skorman00's Avatar
    Join Date
    Nov 2003
    Posts
    594
    ooo, didn't think about that Shamino. Good call.

  5. #5
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968
    you can thank Bubba for this bit of knowledge :d

  6. #6
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968
    my program was doing anywhere between 200,000-400,000 mathematical operations per frame, no wonder it got about 5 fps :\

  7. #7
    Computer guy
    Join Date
    Sep 2005
    Location
    I'm lost!!!
    Posts
    200
    that is for low graphic card or low processor, with high graphic card and high speed processor, these calculations are not big of a deal
    Hello, testing testing. Everthing is running perfectly...for now

  8. #8
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968
    we have a beastly processor... 2.4 gigahurts, it still runs at 5 or so fps...

    oddly enough, at home my p3 dual 400 mhz runs its perfectly smooth, strange..

  9. #9
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    i think the more important question is.. who the heck needs a 4 dimensional array..?!?
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  10. #10
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    that is for low graphic card or low processor, with high graphic
    card and high speed processor, these calculations are not big of a deal
    You are wrong.

    Wasting cycles is still wasting cycles even on a super-computer. And so far you haven't shown me any code that is being processed by the graphics card so it has no relevance as of yet.

    And if it is not a big deal, then why is your code running so slow?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 01-01-2008, 04:07 PM
  2. dynamically allocating 4D arrays
    By Marv in forum C Programming
    Replies: 15
    Last Post: 04-12-2007, 12:34 AM
  3. Crazy memory problem with arrays
    By fusikon in forum C++ Programming
    Replies: 9
    Last Post: 01-15-2003, 09:24 PM
  4. 4D arrays... under what situations would you use them, if at all?
    By toaster in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 06-04-2002, 12:12 AM
  5. 3D or 4D arrays
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 02-25-2002, 06:02 PM