API conventions
When using the EasyAR Sense APIs, you need to follow some conventions. Otherwise, the program may crash, memory leaks may occur, or other abnormal runtime behavior may happen.
Supported languages
EasyAR Sense supports the following languages:
C
Supports C99 and Visual C++, gcc, clang
C++
Supports C++17 and Visual C++, gcc, clang
The only C++17 feature used is std::optional. If you need to use it in a C++11 environment, you can use optional lite, replace std::optional in the interface header files with nonstd::optional, and replace
#include <optional>with#include "nonstd/optional.hpp"Java
Supported only on the Android platform, supporting Java SE 6 and later
Kotlin
Supported only on the Android platform
Objective-C
Supported only on iOS/macOS/visionOS platforms
Swift
Supports Swift 4.2 and later
C#
Supports .Net Framework 3.5 and later, .Net Core, .Net 5+, Mono, Unity/Mono, Unity/IL2CPP
Thread safety model
For each class, unless otherwise stated, its static members are thread-safe.
For each class, unless otherwise stated, its instance members are thread-safe when externally locked, and are not thread-safe when not locked.
For each class, unless otherwise stated, after all other calls to the object have ended, its destructor can be called from any thread, and this is thread-safe.
Memory model
EasyAR Sense internally uses C++ std::shared_ptr for reference counting, and there is a fundamental incompatibility between reference counting and garbage collection, so they cannot be converted seamlessly.
C, C#, Java/Kotlin
Manual reference counting is required. Use dispose to release references to held objects, and use clone to create a new reference from an existing reference.
Pay special attention that parameters passed to EasyAR Sense callbacks are automatically released after the callback ends. If you need to keep them, you must clone them. The reason for automatic release is to support callbacks that contain no logic.
Note that using EasyAR Sense objects in callbacks passed to EasyAR Sense may cause circular references. They need to be manually released as resources (such as files or operating system handles) to prevent memory leaks.
C++, Objective-C, Swift
Use the language's built-in reference counting.
Note that using EasyAR Sense objects in callbacks passed to EasyAR Sense may cause circular references. Use capture by reference, std::weak_ptr, and similar mechanisms appropriately.
String encoding
The encoding of strings used in the interfaces is as follows:
C, C++
UTF-8
Java, Kotlin, Objective-C, C#
UTF-16
Swift
UTF-16 or UTF-8, see Swift documentation