Memory is one of the important resource , we can say its a crucial resource in computers. In a limited amount of memory an operating system tries to satisfy all the applications and the need of memory.
Let us try to understand how a memory looks – the theory and an example simple program to understand the concept in a better way.
Understanding Of Memory
When we say a memory is allocated for an instance ! How exactly you visualise the memory and allocation ?
A memory is array of smallest unit of space which is nothing but a byte of space location. If a variable holds an integer, float or any type of data, it occupies certain set of such memory locations. Typically it looks like below.
In the above memory structure we can see how data is stored in memory.
The String “XYZ” , the number 15 , it looks like at location 12, number 15 is stored, starting from location 21, string XYZ is stored.
If I dig into the depth of it, every thing in computers will be converted into binary , so ‘X’ will be converted into binary which occupies 8 bits , similarly each character will be converted to its ASCII and the ASCII value will be converted to binary ( Ref – http://sticksandstones.kstrom.com/appen.html )
Let us consider one example and try to fill the memory locations
char subjects ;
The above character multidimensional array will holds 2 subjects of 3 semesters each of length 25 characters.
subjects -> will give you 2 subjects of first sem, each subject of 25 characters.
subjects -> will give you 2 subjects of second sem, each subject of 25 characters.
If I assign the subjects to this array , the subject names in memory looks like below
For better understanding just check the below diagram of memory layout