Reload from file example of using 51Degrees device detection.This example shows how to:
- Only maintain a reference to a single EngineHash instance and use the reference to process data.
- Use the EngineHash->refreshData() function to reload the dataset from the same location and with the same set of properties.
- Retrieve a results instance from the engine and release it when done with detecting current User-Agent.
- Use the reload functionality in a single threaded environment.
- Use the reload functionality in a multi threaded environment.
This example illustrates how to use a single reference to the engine to use device detection and invoke the reload functionality instead of maintaining a reference to the dataset directly.
The EngineHash->refreshData() function requires an existing engine with the initialized dataset. Function reloads the dataset from the same location and with the same parameters as the original dataset.
Please keep in mind that even if the current dataset was constructed with all available properties this does not guarantee that the new dataset will be initialized with the same set of properties. If the new data file contains properties that were not part of the original data file, the new extra property(ies) will not be initialized. If the new data file does not contain one or more property that were previously available, then these property(ies) will not be initialized.
Each successful data file reload should be accompanied by the integrity check to verify that the properties you want have indeed been loaded. This can be achieved by simply comparing the number of properties before and after the reload as the number can not go up but it can go down.
The reload functionality works both with the single threaded as well as the multi threaded modes. To try the reload functionality in single threaded mode build with FIFTYONE_DEGREES_NO_THREADING defined. Or build without FIFTYONE_DEGREES_NO_THREADING for multi threaded example.
In a single threaded environment the reload function is executed as part of the normal flow of the program execution and will prevent any other actions until the reload is complete. The reload itself takes less than half a second even for Enterprise dataset. For more information see: https://51degrees.com/Support/Documentation/APIs/C-V32/Benchmarks