Kotlin Language Features Related to Null Handling

Any software engineer with a Java background would find the null handling features in the Kotlin language interesting. Let's summarize this topic with some examples. Nullable types: In Kotlin, types are non-nullable by default. If you want a variable to be able to hold a null value, you need to explicitly declare its type as nullable using the Type? syntax. For example, String? denotes a nullable string, while String represents a non-nullable string. Safe calls (?.): Kotlin introduces the safe call operator (?.) for handling nullable types. It allows you to safely invoke a method or access a property on a nullable object. If the object is null, the expression returns null instead of throwing a NullPointerException. Example: data class Person(val name: String, val age: Int, val address: String?) fun main() {     // Create a person with a nullable address     val person1 = Person("John Doe", 25, "123 Main Street")     val person2 = Person("Jane Doe", 30,

NOTES ON COMPUTER ARCHITECTURE: Some important concepts in computer architecture

virtual address is a binary number in virtual memory that enables a process to use a location in primary storage (main memory) independently of other processes and to use more space than actually exists in primary storage by temporarily relegating some contents to a hard disk or internal flash drive.

In a computer that incorporates memory management, the virtual address differs from the physical address, which is the data location on an address bus that corresponds to a particular cell of primary storage or to a particular register in a memory-mapped I/O(input/output)  device.

In a computer with both physical and virtual memory, a so-called MMU (memory management unit) coordinates and controls all of the memory resources, assigning portions called blocks to various running programs to optimize system performance. By translating between virtual addresses and physical addresses, the MMU allows every running process to "think" that it has all the primary storage to itself. A Translation lookaside buffer (TLB) is a memory cache that is used to reduce the time taken to access a user memory location. A chip has a MMU(memory management unit) that is mentioned above. TLB is a part of the chip’s memory-management unit (MMU).

The TLB stores the recent translations of virtual memory to physical memory and can be called an address-translation cache. A TLB may reside between the CPU and the CPU cache, between CPU cache and the main memory or between the different levels of the multi-level cache. TLB is nearly always present in any processor that utilizes paged or segmented virtual memory.

But what is paged/segmented virtual memory? What is virtual memory? Virtual memory is a feature of an operating system that allows a computer to compensate for shortages of physical memory by temporarily transferring pages of data from random access memory (RAM) to disk storage.

What is a page? In computer systems that use virtual memory, a page is a unit of data storage that is brought into real storage (on a personal computer, RAM) from auxiliary storage (on a personal computer, usually the hard disk) when a requested item of data is not already in real storage (RAM).

More on TLB: Modern processors include a special cache that keeps track of recently used translations. This special address translation cache is traditionally referred to as a translation-lookaside buffer (TLB), although it would be more accurate to call it a translation cache.  If there is no matching entry in the TLB for a page, the page table must be examined. The page table either supplies a physical page number for the page (which can then be used to build a TLB entry) or indicates that the page resides on disk, in which case a page fault occurs.

Another definition of TLB: A cache that keeps track of recently used address mappings to try to avoid an access to the page table.

Leakage Energy: Power consumption is now the major technical problem facing the semiconductor industry. In comments on this problem at the 2002 International Electron Devices Meeting, Intel chairman Andrew Grove cited off-state current leakage in particular as a limiting factor in future microprocessor integration. Off-state leakage is static power, current that leaks through transistors even when they are turned off. It is one of two principal sources of power dissipation in today’s microprocessors. The other is dynamic power, which arises from the repeated capacitance charge and discharge on the output of the hundreds of millions of gates in today’s chips.

Reference:
Patterson, David A., and John L. Hennessy. "Computer organization and design." Morgan Kaufmann (2007)

Comments

Popular posts from this blog

Trie Data Structure and Finding Patterns in a Collection of Words

swapLexOrder: Finding lexicographically largest string

Virtual Memory