Skip to main content
Variables

  • Variable allocation refers to when space in memory is allocated (ie set aside) for the variable
  • Different kinds of variable have different allocation and deallocation protocols
  1. Package level variables are allocated/deallocated when the program begins/ends
  2. Local variables are allocated/deallocated each time the routine begins/ends execution following a stack protocol 
    1. When the procedure is called, the locals are stacked and when it exits, they are popped
    2. Example: 
      1. Procedures A, B, and C have locals X, Y, and Z, respectively.
      2. if A calls B which calls C, then C's locals are on top of the stack and A's locals are on the bottom of the stack
  3. Anonymous variables are allocated when explicitly created by the program and deallocated when explicitly destroyed by the program
  • When known: 
    • Allocation of package level are can be determined at compile time  (ie it is static)

    • Allocation of locals and anonymous are not known until runtime (ie it is dynamic)

Memory Organization

  • Memory is divided into three areas: static, stack, heap (not related to heap sort or heap data structure) 
  • Each area holds a different kind of variable
  • static: holds package level variables.   (In C and C++, variables declared as static are declared here.)
  • stack: for local variables
  • heap: for anonymous variables   The pointer  variable is usually a local variable

Comments

Popular posts from this blog

Next.js vs react

Next.js builds upon React and offers several advantages over using React alone: Key Advantages of Next.js over React: Server-Side Rendering (SSR) and Static Site Generation (SSG): Next.js provides built-in support for SSR and SSG, leading to faster initial page loads, improved SEO, and better performance for content-heavy applications. Simplified Routing: Next.js offers a file-based routing system, making it easier to manage routing configurations compared to React, where you might need to use additional libraries like React Router. Automatic Code Splitting: Next.js automatically splits your JavaScript code into smaller chunks, optimizing page load times by loading only the necessary code for each page. API Routes: Next.js allows you to easily create serverless API endpoints within your Next.js project, simplifying backend integration. Image Optimization: Next.js includes an optimized image component that automat...

React JS Basics

  What are side effects in React? In React, side effects are operations that interact with external systems or cause changes outside the component's rendering process. These can include: Data fetching: Retrieving data from APIs or other sources. Subscriptions: Setting up listeners for events or data changes. Timers: Creating timers for delayed actions or animations. DOM manipulation: Directly modifying the DOM (rarely used in modern React with declarative approach). Why use useEffect ? In class-based components, you would typically use lifecycle methods like componentDidMount , componentDidUpdate , and componentWillUnmount to handle side effects. Functional components don't have these methods directly. The useEffect Hook provides a way to manage side effects in functional components. It allows you to run a function after a component renders (or re-renders) and optionally clean up any resources created by that function before the component unmounts. How does useEffect wor...

GIT Branching strategies

  What are GIT branching strategies? GIT branching strategies are patterns or approaches that tech teams use to organize & manage their code through different branches in a GIT system. Each strategy defines the rules & guidelines for the creation, naming & merging the branches for facilitating collaboration, stability, & release management. In this article, we're going to discuss  git branching strategy best use cases, hands-on on git, as well as the git branching strategies we follow. Along with recommendations on how to use git to accomplish work in a consistent and productive manner. ‍ GIT What are the different GIT branching strategies? Here are some commonly used git branching strategies: Master branch This is the  main  branch and one of the repository in which we have the latest stable code of production.   General rules: - Access to direct merge is restricted - Best practice is to create a CI/CD pipeline to merge code into this ...