int state[6244]!!!

This is a discussion on int state[6244]!!! within the C++ Programming forums, part of the General Programming Boards category; Hi and thx for any help, I need to store the integar values of a screen(1280x1024)into an array,but the array ...

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    3

    int state[6244]!!!

    Hi and thx for any help,

    I need to store the integar values of a screen(1280x1024)into an array,but the array must be 6244 elements long.
    I checked its sizeof and its 2293672 bytes big,2293kb.
    This sounds absurd or maybe its not so absurd,can anyone tell be if this is unrealistic programming and i should find another way.

  2. #2
    Registered User
    Join Date
    Apr 2007
    Posts
    3
    My first post here is obscure and misleading,so Ill explain better,and if I get any replys Ill be a bit surprised and the glory will be all yours.

    what Ive done is made a 2d array[48][128] which is the size of the screen,and that array[48][128] will be filled with integars that refer to a description of a room,(so pc moves into x13,y13 which holds the value of 3,which will give the description of a small passage).

    The value of each element of the 2d array is randomly made by a rand function that needs to have an array 6244 elements long so it can assign a value to all the 2d array elements.

    dice[6244] is that single dimensional array in question,it would hold that many random numbers and assign them to 2d array[48][128].

    dice[6244] when initialised takes 2293672 bytes of space,my question is,is that a bad thing for an application where speed isn't an issue.
    It sounds like a lot of space for one array to have.

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,112
    Are you sure of the size? If it is an array of int, then I believe the size would be 6244 * 4 = 24976 bytes, assuming sizeof(int) is 4 bytes.

    2293672 / 6244 is about 367.34, and I find it odd that each element in the array would have a non-integral number of bytes.

    EDIT:
    Oh, and 48 * 128 = 6144
    So, if you need 6144 ints, and sizeof(int) is 4, then your array would be 6144 * 4 = 24576 bytes = 24 KiB.
    Even if sizeof(int) = 8, your array would only be 48 KiB, a far cry from the 2.1 MiB that you propose it takes up.
    Last edited by laserlight; 04-07-2007 at 01:55 AM.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    Registered User
    Join Date
    Apr 2007
    Posts
    3
    thx laserlight,yeah,2144...
    just one question,do you or anyone here think an array of 6144 elements is bad programing,or is it normal?

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,746
    It's nothing to worry about on todays desktop machines.
    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. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03:39 PM
  2. Replies: 2
    Last Post: 03-24-2006, 08:36 PM
  3. getting a headache
    By sreetvert83 in forum C++ Programming
    Replies: 41
    Last Post: 09-30-2005, 06:20 AM
  4. Quack! It doesn't work! >.<
    By *Michelle* in forum C++ Programming
    Replies: 8
    Last Post: 03-02-2003, 12:26 AM
  5. easy if you know how to use functions...
    By Unregistered in forum C Programming
    Replies: 7
    Last Post: 01-31-2002, 07:34 AM

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