Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

anotherfantasy

How exactly does RAM work?

This topic is 6021 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?)

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
[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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
ANd on the amount of ram in question...

-Maarten Leeuwrik
=================
[Illiad] J.R.R TOLKIEN ACHIEVES 40,000 RPM IN GRAVE

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 ).

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!