codescracker


c++

C++ Free Store



« Previous Tutorial Next Tutorial »


Free Store is a pool of unallocated heap memory given to a program that is used by the program for dynamic allocation during the execution of program.

Every program is provided with a pool of unallocated heap memory that it may utilize during the execution. This pool of available memory is referred to as free store of the program.

The allocated free store memory is unnamed. Objects allocated on the free store are manipulated indirectly through pointers. Another aspect of free store is that the allocated memory is uninitialized. The programmer is responsible for initializing it explicitly.

The free store memory is allocated through the use of new operator and deallocated through delete operator.

Free store memory (dynamically) allocated during run-time and static memory allocation takes place during compile-time. An object's life time i.e., as long as the object remains in the memory during the program execution, is known as an object's extend. Global variables or the variables having file scope are spoken of as having static extent. That means, the storage is allocated to them before the program's start-up and remains bound to the variable throughout the program execution.

Variables having local scope are spoken of having local extend. Storage is allocated to them at each entry into the local scope (i.e., as soon as their local scope starts); and on exit (from the local scope), the storage is freed up. A local variable with static specifier has static extend.

Note - The storage allocated through the use of new operator remains bound to the object until it is explicitly deallocated by the programmer.

Objects that are dynamically allocated on free store as spoken of as having dynamic extend.

That means, the dynamically allocated objects do not have any predefined scope. They remain in memory until explicitly removed using delete.


« Previous Tutorial Next Tutorial »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test