How exactly does RAM work?

Started by
33 comments, last by anotherfantasy 22 years, 1 month ago
ok... i know wut ram is. just not too sure about the technical stuff. when i run a single file program that has only 1 exe, does that whole program get loaded into the ram? the main question is... if i make a tetris game that has a 2 player mode, i''m thinking of making 2 display/control classes, one for each player. (each will have the blocks, the movements, the scores etc. ) is there some way to only declare the second class if you are in a 2 player mode or do you have to declare both and just not use one? (one will be active and the other sits in the RAM?)
There''s an astronomical difference in being the best and being the best of the best.
Advertisement
Try declaring the classes in an array.

But with ram, that''s a WHOLE different story. It''s hard to explain, but it''s really clear in Assembly Language Step-by-Step by Jeff Dunteman (WILEY). Or you can go to www.Howstuffworks.com
---START GEEK CODE BLOCK---GCS/M/S dpu s:+ a---- C++ UL(+) P(++) L+(+) E--- W++ N+ o K w(--) !O !M !V PS- PE+Y+ PGP+ t 5 X-- R tv+ b+ DI+ D G e* h! r-- !x ---END GEEK CODE BLOCK---
[EDIT: Statements retracted]

In any case, here's the deal. RAM usage is not much of an issue in programming. It does get to be in big projects, but usually more with the graphics. But to answer your question:

The best way to do this is through pointers. Pointers allow us to be able to create the class, but the class is not automatically allocated memory. We need to create it ourselves.
    CPlayer* Player1 = NULL;CPlayer* Player2 = NULL;void InitPlayers( BOOL TwoPlayer ){Player1 = new CPlayer();if( TwoPlayer )Player2 = new CPlayer();}    


-----------------------------
The sad thing about artificial intelligence is that it lacks artifice and therefore intelligence.

Edited by - Promit on February 18, 2002 5:43:46 PM
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
quote:Original post by anotherfantasy
does that whole program get loaded into the ram?

I think the answer to this question depends on the operating system.

"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
ANd on the amount of ram in question...

-Maarten Leeuwrik
=================
[Illiad] J.R.R TOLKIEN ACHIEVES 40,000 RPM IN GRAVE
You will always have to create both classes - classes exist in code and are like blueprints for building objects.
//class
class chicken {
...
}

However you can use the classes to create as many or as few objects as you wish.

//object
chicken myChicken;
chicken yourChicken;

if you want to dynamically allocate objects youl need an object pointer

chicken *chickenPtr;
...
chickenPtr = new chicken();

what is in RAM and what isn''t is controlled by the operating system, things will be swapped to the hard drive according to the algorythm the operating system is using - the code and data that are currently being used will be in RAM (usally in blocks) but like Promit says who cares unless your are making one hell of a game and given the question I''d doubt it (no offence intended).


Sephwrath.
Dont you get it there is no remote
quote:Original post by Promit
2) You are one of those people that acts like thye know a whole lot and actually know nothing.


Where do you get off suggesting something like this? It''s completely unneeded and pointless. Not to mention you''re in no position to patronize.
quote:Original post by Promit
I didnt imply either one as being more correct, and if hes just veyr confused, im cool with that. Notice i said "or".

I like to poke at anyone who is #2, even if the poster is not #2...no offence to anotherfantasy.


There was still no reason for you to even have said it in the first place...

It''s like me finding some random post by a kid who''s seeking help and saying

"Well you''re either looking for an answer, or you''re actually plotting to overthrow the government. Now, getting to your question..".

It''s completely random, irrelevant, and pointless.
look down kids, as soon as a program loads its in ram or if the ram is too full then it goes on the stack (or virtual memory)

there is no difference between

ClassX a;

AND

ClassX* a;
a = new ClassX;

they are both implying the same memory allocation, both are dynamic at execution but one will load in a particular region of memory wich may be the local execution of a function or global to a program, i suggest to people interrested into learning about this look into these sample keywords :

call stack
stack pointer
memory allocation
virtual memory

or go to school in computer science, these are covered in the begining of object oriented programming classes (well in quebec at least ).
May the code be with us !
quote:Original post by hotdot
as soon as a program loads its in ram

Not necessarily.
quote:
or if the ram is too full then it goes on the stack

No it doesn''t.
quote:
there is no difference between

ClassX a;

AND

ClassX* a;
a = new ClassX;

... except that the first one is created on the stack, and the second one is created on the free store, and will persist beyond its local scope. Seems like a pretty big difference to me.
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers

This topic is closed to new replies.

Advertisement