Link to home
Start Free TrialLog in
Avatar of Mike Eghtebas
Mike EghtebasFlag for United States of America

asked on

image, memory location (visual explanation)

I have not studied C or C++ yet. I have located the following image from Web and I want to make sense out of its structure.

height      175  0x0031F1
weight      73      0x0031F4
age              24      0x0041F1


Obviously, height, weight, and age are variable names and the matching numbers are their values.

Q1: Are the third column memory addresses?

If so, I am trying to make an image like:

Following are recorder on [ blank ] section of the memory:      name what blank is?
 
Resume  0x0031F1
height      0x0031F4
weight      0x0031F9
age              0x0041F1  


And then have:

Following are memory locations with variable values:
mem.address               binary values
0x0031F1   01010111000101011100010101110011        <-- these do not translate to something real in resume.txt
0x0031F2   01010111000101011100010101110011
0x0031F3   01010111000101011100010101110011       <-- to read: 0x0031F5, Continuation address for resume.txt
0x0031F4   01010111000101011100010101110011       <-- should change to be 175 (weight)      
0x0031F5   01010111000101011100010101110011       <-- resume.txt continued here
0x0031F6   01010111000101011100010101110011
0x0031F7   01010111000101011100010101110011
0x0031F8   01010111000101011100010101110011     <-- to read: 0x0041F5, Continuation address for resume.txt
0x0031F9   01010111000101011100010101110011       <-- should change to be 73(height)  
0x0041F1   01010111000101011100010101110011       <-- should change to be 24(age)  
...
0x0041F5   01010111000101011100010101110011    <-- resume.txt continued here
...
...

Q2: Could you please comment on my take. If more or less accurate, give me a link with image (for visual explanation)?  

Thank you.
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Since you have presented this info out of context, it is difficult to say exactly what it is.  In particular, the "mem.address  / binary values" section presents 32-bit binary values but PC/Intel memory addresses would increment by 4, not by one.  There are other types of CPUs that would present it that way.
Avatar of Mike Eghtebas

ASKER

phoffric,

re:> Are you taking courses, or self-studying?
It is self-study.

To all,

Lets ignore my setup because it seems it had many issues. Instead, if you may show me how a variable is stored in binary form in the RAM or disk.

My understanding is:

1. variable names or file names are listed somewhere (may be in FAT?) and the variable names get associated with some memory addresses.
2. The memory address like d01 associated with variable age, for example, records the variable value for age, for example 73, at memory location d01.
3. In the case of a file, for instance, as opposed to variable age, there will be many bytes at different addresses because when resume.txt was saved 5 minutes ago the computer continued recording some other variables after resume.txt memory space thus interrupting memory use for resume.txt.

Basically, I am trying to build a case why oop (object oriented programming) could speed up read/write operation because in object oriented programming the data pretty much gets a block of continuous memory space. This occurs upon substantiation of the object.

I know, there are many other beautiful aspects of oop (95%) and possibly no one talks about the speed of read/write aspect (5%).

I am looking for the possibility of oop development was incidental (accidental) and early goal was just to speed up read/write operation.

This may be a know fact but unknown to me hence this reaching out to the experts. Regardless what the result of this investigation is, I find much success explaining oop by telling them:
'
A- How variables stored on the disk or ram (the understand this easily because of the illustration I use).
B- How some file get fragmented which is not good (they also understand the logic in step B as well).
C- So what if we block a section of memory to store object related data continuously. (Finally they get the concept of OOP with no ambiguities)

So, with this intro in mind, in order to refine and improve my presentation to others:

Question: Could you please illustrate how variables or files are stored in memory (ram or disk)? Please make references to memory address, variable name, and possibly generic 1 and 0 bits regardless they are 4 or 32 bits.

Thank you,

Mike
FYI: My previous post got edited.
You are very far from your goals at this point.  Your concept of how memory is used is pretty much wrong.

You need to understand how CPUs operate before you can understand any part of your questions.  Please look first at how an x86 CPU (for example) operates.  http://www.cs.virginia.edu/~evans/cs216/guides/x86.html  Then look at the Calling Convention section of that article.

Programs run in RAM.  They can load and save data to and from disk but they don't 'run' there so this has nothing to do with FAT or NTFS or any other disk format.

"OOP with no ambiguities" doesn't make any sense.  OOP can be a difficult concept to understand well enough to use.  And unless you are an extremely expert assembly language programmer, you will be using a higher level language like C++ to do it.
re:> OOP can be a difficult concept to understand

You are making my point. It is difficult but at the same time it is very easy to understand.

It gets easy when you compare simple variable memory usage vs reference type memory usage. From your response, I gather that you will never would want to take a look at my direction and wanting to see my point of view.

I do not need to understand how a cpu functions. You tell me how it uses (where it plants) data for simple variable vs reference type variable?

I want to know where 24 and 2010 are stored:

int age = 24;
Car myCar = new Car();
myCar.Year = 2010;

I eventually will learn all about cpu etc. But for now my concern and question is how the memory maps visually differs for 24 and 2010?

After all, objects (in oop) are nothing other than place (block) you store data (values, method related instruction etc).

Regards,

Mike
I appreciate the link, I will read it through to understand it but it surly will take quite a bit until I get the full picture. But because you are familiar with the subject, You probably will not have any problem answering my question which is:

int age = 24;
Car myCar = new Car();
myCar.Year = 2010;

Question: How the memory usage could be illustrated for for 24 and 2010?

Thanks
Unfortunately, the original question is not answerable.  I'm glad you found the memory images, they may help you understand things.

I have been dealing with memory chips and concepts since about 1979.  I built hardware machines that cycled through memory data to run hardware based programs.  Then I programmed microprocessor trainer machines in HEX where you had to create your own memory references to make things work.  Then I built microprocessor systems and programmed them in assembly language.  After that I programmed PCs in assembly and C.

When I say that you need to understand how CPUs address memory to understand your questions, I really mean that.  How CPUs handle memory instructions are the basis for how we handle variables in memory.  

In your last comment, "Car myCar = new Car();" implies a class definition.  The last time I tried to figure that out at a low level, it turns out that class definitions are all in some way inherited from a basic class built in to the language.  The only way to find out where "myCar.Year = 2010;" exists is to compile to assembly language and go thru the listings until you find it.  It is not going to be a simple, easily identifiable, location because it is something the compiler generates when it creates the class structure.
Dave,

I make it easy.

varaible         memory            
names        address names
age                    d1         <-- this is memory location to look for the value of age.
v1                      d2
v2                      d3
myCar               d4


memory         binary
address         values
d1                    24   (in zeros or 1 or any acceptable form in bytes)
d2                  
d3
d4                    d13           <-- this is a reference type variable, therefore it asks you to go to
.                                              address d13 for the data relating to myCar
.
.                  __________
d13            |              |
.                 |              |     <-- this section of memory is put aside for use for myCar the moment it was instatiated.
.                 |              |
.                 |              |
.                 |              |
.                  ------------
.d100

Now, all I want is to improve this image by giving a change to parts that are okay and removing or flagging parts that are absolutely wrong.

Imaging you are explaining it to a 6-year old kid. If it can not be explained to 6 year old kid, then I as you to try it to see how it works out.

Thanks,

Mike
ASKER CERTIFIED SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
type in my last post ... imagine  not Imaging
So it seems you agree in some parts. does this passes a sanity check?

Is there a way to improve this (while keeping it still simple)?

I do not know much about pointers; could we say d13 here is the pointer to myCar object?

Thanks,

Mike
OOP classes are not simple.  Simple variables for binary values like numbers can be simple.  But anything more is not so simple.  Character storage is not so simple because you have to keep track of the string size somehow.  And when you get to reading data from files, you get into 'memory allocation' which is also not so simple.  When you pass data to Function calls, it is passed 'on the stack' (which is described in that article) as temporary data.  Since a class has features similar to a function call, data passed to a class variable or function are also passed on the stack and the class routines decide what to do with it.
And I don't talk to six-year olds.
Thank you for putting up with me.

I basically say to people to whom I explain oop:

- this is how simple variable works (age=24 for example)
- and this is how reference type (myCar) works.

It washes away the initial complexity and fear. The warm up to the idea and learn more about it while anchoring with the idea that myCar is a data storage tool plus more.

Thanks,

Mike
You're probably doing fine, it takes some effort to work thru these things.  I've been working in electronics and computer for over 35 years now.  Always something new to learn.