Instance

  • In C++ object live in the memory where are they are instantiated.
  • In Java the objects are allocated in heap memory. The reference to the allocated heap memory is stored as value on the stack. The object in the heap memory contains a table with vptr that points to the functions in the static memory.

Create an Singleton Instance

class SingleTon
{
};


SingleTon* SingleTon::getInstance() {
    static SingleTon instance;
    return &instance;
}