Skip to main content

C: A personal way of understanding STACK

Used this to explain stack to my girlfriend and it worked quite well......

The Stack UnderstandingTo call a function

When calling a function, the stack works as below:

1. Function reached, push arguments(to use) on the stack(inventory), push return address on stack(location of soldier)
2. Jump to function code(take a ride to blacksmith)
3. Increment stack pointer to allow space for local variables (pick up materials needed to sharpen sword)
4. Execute code (sharpen)
5. Pop local variables and arguments off stack (throw away used materials from the inventory)
6. Jump to return address (take a ride back to the soldier and give him the sharpened sword)

So, we can translate this into a more interesting scenario to understand (at least it worked for me):

1. Mission accepted :
           Take the sword from the soldier, sharpen it and take it back to the soldier
2. Put sword into inventories, record where the soldier is at, take a ride to the blacksmith
3. Use a bigger bag to put all the materials needed to sharpen the sword
4. Sharpen the sword
5. Dump all used materials from the inventory

6. Give the sword back to the soldier


Popular posts from this blog

Understanding database [9] : Choosing indexes

Understanding database 9 : Choosing indexes When choosing indexes, we choose the best plan that suits for the queries, and look for additional indexes that may potentially upgrade upon that. Before creating, we must also consider the impact on updates in the workload, such that indexes take disk space. For a query, the WHERE clause are the main focus point to make indexes on, where exact matches suggest a hash index and range queries suggest a tree index. Clustering is extremely helpful when it comes to range queries, and may also help with equality queries if there are duplicates. Search keys with multiple attribute should be considered if a WHERE clause contains multiple conditions, and the order of attributes is important for range queries. Searching may become ‘index-only’ with such indexes.

Understanding database [6] : Clustered Index

A clustered index is what is good for a range search over a range of search key values, and the index entries and the rows are ordered the same way, which is different from unclustered indexes (secondary indexes). To use a clustered index, we use the index to locate the first index entry at the start of the range, which where the first row is located at. If the index is clustered, subsequent rows will be stored in successive locations with the ordering , therefore it may minimize the page transfers and maximizes cache hits. For one table, there may only be one clustered index, whereas there can be as many unclustered indexes as you may want  to create. Unclustered indexes aren ’ t as good as clustered, but they might become necessary when it comes to finding for other attributes apart from the primary key. Smaller topics : Dense index & Sparse index When we say sparse index, we mean that there is an index entry for each page of the data file. With this structuring