RAM vs Cache & Registers

This is a discussion on RAM vs Cache & Registers within the C++ Programming forums, part of the General Programming Boards category; Does the compiler typically automatically use RAM, or do you have to explicitly tell it to use RAM? Does using ...

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    28

    RAM vs Cache & Registers

    Does the compiler typically automatically use RAM, or do you have to explicitly tell it to use RAM? Does using ram have something to do with dynamic allocation.

    Sorry if this seems newbish, I just really want to know and I can't seem to find a clear answer.

  2. #2
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    It will use registers for performing operations (there is no other option). The processor will automatically cache the things in RAM which it thinks will be accessed next. Any part of your program that doesn't fit in the registers (which will be most of it) will go to the RAM, or virtual memory. It's kinda OS dependent... but no, you don't need to worry about it when you're coding.
    Away.

  3. #3
    lyx
    lyx is offline
    Amateur
    Join Date
    Sep 2003
    Posts
    228
    Register & cache use is part of the optimization process, some compilers will try to put as much as possible in the register and let the memory as much as possible in the cache when it is necessary to limit the acces to the RAM.

  4. #4
    Registered User
    Join Date
    Jan 2003
    Posts
    311
    To further confuse you, the volitile keyword can be used to force the compiler to place something that it might be tempted to ignore or use a register for in ram. For example
    Code:
      int max = 8;
      for(int i=0; i < max; ++i) ...
    here, as long as the compiler sees that max is never modified in the body of the for loop the compiler might very well simply compare i to 8 at every step of the loop, and might even unroll the loop for you (duplicateing the body of the loop and loop over both 4 times)

    volitile int max = 8;

    forces the compiler to name a location in ram "max" and read this location every time through the loop. Normally we don't care where things live, this is exactly the reason we are using a compiler rather than writing assembly language really, computers are really good at making these sorts of decisions.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. RAM upgrade
    By BobS0327 in forum Tech Board
    Replies: 6
    Last Post: 12-10-2008, 07:14 AM
  2. need help with cache simulator!
    By dtogers123 in forum C Programming
    Replies: 3
    Last Post: 04-30-2008, 06:18 PM
  3. Resource manager tree
    By VirtualAce in forum Game Programming
    Replies: 23
    Last Post: 09-07-2007, 10:27 PM
  4. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 01:30 PM
  5. cache miss/hit
    By xddxogm3 in forum C++ Programming
    Replies: 3
    Last Post: 05-07-2007, 06:51 PM

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