Skip to main content

Memory Virtualization



Address Spaces

    
       The range of virtual addresses that the operating system assigns to a user or separately system assigns to a user or separately running program is called an address space.

Ex: A device, A file, A server or a networked Computer.

Memory API 

 
The API achieves this by estimating the amount of memory resources that are in use.

  Eg. Malloc/ Free, calloc/realloc , brk/sbrk , mmap/mumap.


malloc()

Allocate a memory region on the heap.

      Argument
  • size_t  size : size of the memory block(in bytes).
  • size_t is an unsigned integer type.
       Return
  • Success: a void type pointer to the memory block allocated by malloc.
  • Fail : a null pointer.

sizeof()          

 Routines and macros are utilized for size in malloc instead typing a number directly.

free()

    Argument
  •    At pointer to a memory  block allocated with malloc.
       Return
  •   none.

Memory leak

  • A  program keeps allocating memory without freeing it.
  • A program runs out of memory and eventually is killed by OS.

Dangling pointer

Freeing memory while it is being used. 
  • A program accesses to memory with an invalid pointer.

malloc()

Allocate memory and zeroes it before returning.

realloc()

Change the size of memory block.

brk/sbrk

break: The location of the end of the heap in address space.
  • brk is called to expand the program's break.
  • sbrk is similar to brk.