API lifetime#
Primary ItalaApi functionalities are accessible via an abstraction called system, which is the root of the API. To initialize the ItalaApi, the client code must create the system instance.
Warning
The client code is responsible for the system instance lifetime. The client code must create the system before using it and destroy it when it’s no longer required. As long as the system instance is alive, the ItalaApi can be used.
The CreateSystem
free function initializes ItalaApi and returns a pointer to the system interface ISystem
. The Dispose
function of the ISystem
interface works exactly like a delete operator: it destroys the system instance.
#include <ItalaApi/Itala.h>
int main()
{
Itala::ISystem* pSystem = Itala::CreateSystem();
//Use the ISystem interface
pSystem->Dispose();
pSystem = nullptr;
return 0;
}
It’s good practice to set the ISystem
pointer to null after the system instance is destroyed to avoid double Dispose
calls and other memory corruption problems.
Since the system is the root of the API, it is unique and only one instance can be created at a time.