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

OWASP API Security Top 10 vulnerabilities 2023

API Security Do's and Don'ts Don't trust input data for an API and do validate all inputs. Ensure you understand security and keep sensitive data out of code. Don't hardcode keys/tokens Don't reveal useful info in error messages. Don't have hidden/unadvertised features. Don't filter data in UI - control at app level Don't confuse authentication and authorization Always use API gateways to control access and traffic Do require API documentation. Do expect users/hackers to find and use undocumented endpoints Do continuous testing - attack simulation, test configs, fuzzing, injections OWASP API Security Top 10 Vulnerabilities 2023 API-1:2023 - Broken Object Level Authorization: BOLA is still the leading vulnerability that plagues APIs. When data objects do not have sufficient access controls in place, resources can be accessed by unauthorized users. API-2:2023 - Broken Authentication  Broken Authentication contains all vulnerabilities associated with auth...

Load Balancer Routing Algorithms - Draft version

The main purpose of the load balancer is to distribute the traffic evenly across multiple servers. The Load Balancer promises the efficient usage of the back-end servers without overloading and not keeping the server in busy times. Avoiding the server overload will reduce the downtime. Table of Content: Different types of LB Algorithms used by ALB ALB Features  Questions Configuring ALB in AWS  Creating K8S config files Factors to consider to ALB design There are different types of load balancers: Application Load Balancer (Layer 7) Network Load Balancer Global Server Load Balancer Let's narrow our discussion to Application Load Balancer(ALB). The ALB operates on layer 7 of OSI model.   Algorithms used by ALB are: Round Robin   Least connections Weighted Round Robin IP hash Least Connections Response time The ALB evaluates incoming requests to ensure efficient and reliable traffic distribution. LB has to ensure. High availability Scalability Performance opt...

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...