BimRv SDK: Use Unload Mode

Yury Lebedev

June 30, 2023

A special unload mode reduces memory usage during file load and further work with the BimRv API. By default, all file elements are kept in memory after initial reading from the file stream, but this mode serializes them back to a special deposit storage, from which they are extracted when opening an element. This feature reduces memory usage by almost half but may cause a serious performance decrease during file load.

Enabling the unload mode also implies usage of smart pointers for all elements that were opened using the API. It is generally recommended to use smart pointers, but for unload mode it is crucial as opened elements are released immediately if handled with a raw pointer.

BimRv SDK contains methods for working with unload mode. For example, to check if unload mode is enabled, call the unloadEnabled() method. The unloadCondition() method allows you to create a condition for when a file is unloaded.

To check if the unloadCondition() function can be cached, call the unloadCoditionCanBeCached() method.

Additionally, the OdRxSystemServices extension has an option to redirect the deposit storage to a file and specify the data synchronization rate. To check if the redirect is possible, call the useDisk() method, and if it returns true, proceed to unload the file path with the unloadFilePath() method. And to customize the indexing rate, use the indexingRate() method.

By default, unload mode is turned off. Note that the unload mode options should not be changed if any file has been opened using BimRv SDK.

A sample extension can be found in the BimRv/Extensions/ExServices/ directory, which includes header and source files named ExBimSystemServicesPE that contain the implementation. This sample implementation allows you to enable unload mode in OdaBimApp.

The COdaBimApp class contains all the necessary ODA services itself, but each of them can be represented by an independent implementation.

class COdaBimApp : public CWinApp
                 , public OdRxObjectImpl<ExSystemServices>
                 , public OdRxObjectImpl<OdExBimHostAppServices>
                 , public OdRxObjectImpl<ExBimSystemServicesPE>
                 , public OdExBimHostAppProgressMeter

Any custom implementation should be registered as an OdRxSystemServices protocol extension after loading the OdBmLoaderModuleName module but before opening a file.

// Initialize Runtime Extension environment
odrxInitialize(this);

// Load ODA BimRv modules
::odrxDynamicLinker()->loadModule(OdBmBaseModuleName);
::odrxDynamicLinker()->loadModule(OdBmLoaderModuleName, false);

// Disable Unloading mode initially
setUnloadEnabled(false);
setUseDisk(false);
OdRxSystemServices::desc()->addX(OdBmSystemServicesPE::desc(), static_cast<OdBmSystemServicesPE*>(this));

In OdaBimApp, choose File > Unloading mode to choose two unload options: whether to unload objects from memory after use, and whether to cache temporary data on disk. Unload mode is enabled if either option is turned on. Note that due to its implementation, you cannot change any unload options if a file is open.

Find out more in our documentation.