Thread: int state[6244]!!!

  1. #1
    Registered User
    Join Date
    Apr 2007

    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
    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
    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.

    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 12:55 AM.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    Registered User
    Join Date
    Apr 2007
    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 int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    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.

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, 02: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, 05: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