Pointers and Dynamic Memory – An introduction

Some crucial part to know about memory are Pointers and Dynamic memory to troubleshoot within the infrastructure of the memory. To grasp how pointers work, we need to understand how data types are stored in computer memory. When a program executes, memory is interpreted as RAM. Let’s say we have a 1GB RAM. Each byte in the memory has an address. We can interpret it as each part of a human memory having its neurons associated with parts of your body.

10649895_1276359969046339_6283119763362422098_n

The first byte of the memory has an address called Zero. The Addresses of each byte keeps on incrementing the more you move on to a different level of bytes within the memory architecture. Memory, when assigned to a program, can be divided into four segments that are HEAP (pool of memory), STACK (function calls and local variables), STATIC (global variables – not stored inside a function) and CODE (instructions).

Now, let’s say we have to declare a variable in our program. For example, a variable called “a” of type integer – int a; the computer allocates a certain amount of memory for a particular variable and depending on how many data types are used, the memory will be allocated accordingly. However, there are other aspects to be taken into consideration by the computer to allocate more memory. Ex. the compiler itself.

A pointer acts as a variable that stores the address of another variable. How? Integer A is allocated to address 100, 101, 102, 103. The computer will query its lookup table where the information is stored.

Tagged
Nitin J Mutkawoa https://tunnelix.com

Blogger at tunnelix.com | Founding member of cyberstorm.mu | An Aficionado Journey in Opensource & Linux – And now It's a NASDAQ touch!

You May Also Like

More From Author