RAM question

This is a discussion on RAM question within the C++ Programming forums, part of the General Programming Boards category; How much RAM does it take for every integer? What about a char or char[256]? I haven't been able to ...

  1. #1
    1.b4 e5 2.a3 d5 3.d4 exd
    Join Date
    Jan 2003
    Posts
    167

    RAM question

    How much RAM does it take for every integer? What about a char or char[256]? I haven't been able to find any decent tutorials on objects (i guess i can initialize one but i cant get them to interact) i have been simply declaring lots of variables, but I assume that wastes memory
    AIM: MarderIII

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >How much RAM does it take for every integer?
    sizeof (int) bytes.

    >What about a char or char[256]?
    sizeof (char) bytes and sizeof (char) * 256 bytes.

    >i have been simply declaring lots of variables, but I assume that wastes memory
    Don't worry about it, memory is in abundance currently and I seriously doubt you'll be writing anything memory intensive soon if you had to ask this question.
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    each compiler (Operating system?) uses a different amount of memory to store any given type. Some will use 4 bytes to store an int, some 8, some 16, and maybe even some 32; who knows. Using the sizeof() operator as indicated by Prelude will let you know what your compiler/system uses.

    who knows, I may even be mixing up bytes and bits. Doesn't matter. sizeof() is the key to finding out.

  4. #4
    Cat
    Cat is offline
    Registered User
    Join Date
    May 2003
    Posts
    1,571
    32 byte long integers? I don't know of any processor that uses 256-bit numbers; certainly not natively.

    On your run of the mill 32-bit x86 machine, compiled for MS Windows, the primitives take the following amounts of space:

    char - one byte (8 bits)
    short - two bytes (16 bits)
    int - four bytes (32 bits)
    long - four bytes (32 bits)
    Pointers - four bytes (32 bits)

    There are also 64 bit data types, but they aren't primitives.

    It does completely depend, though, on the platform you develop on. In general, char is the size of the characters (usually 7, 8 or 9 bits), int is the size of the processor's accumulator register. Sizeof() is the foolproof way to know how much space your variable will take.

  5. #5
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    I'd consider a double both primative and 64 bit.

  6. #6
    Registered User dalek's Avatar
    Join Date
    May 2003
    Posts
    135
    I don't know of any processor that uses 256-bit numbers
    Absolutely, 640K will be enough memory to take us into the 21st century and beyond!

    I think elad was just being rhetorical..

  7. #7
    Cat
    Cat is offline
    Registered User
    Join Date
    May 2003
    Posts
    1,571
    Originally posted by SilentStrike
    I'd consider a double both primative and 64 bit.
    Umm... d'oh? I guess I wasn't thinking about floating-point numbers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. another do while question
    By kbpsu in forum C++ Programming
    Replies: 3
    Last Post: 03-23-2009, 12:14 PM
  2. RAM upgrade
    By BobS0327 in forum Tech Board
    Replies: 6
    Last Post: 12-10-2008, 07:14 AM
  3. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  4. Compaq RAM
    By ober in forum Tech Board
    Replies: 15
    Last Post: 02-28-2003, 04:23 PM
  5. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 08:22 PM

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