• Uncategorized

    A C++ Smart Pointer wrapper for use with JNI

    Introduction In this article, I'll propose a solution for managing native C++ resources from JNI using smart pointers. While Smart Pointers can't be useful from Java, because of the limits of the Java memory management, it may be required by the native library to maintain allocated resources through shared_ptr or unique_ptr, for example because classes derive from std::enable_from_this. Since there is a fixed pattern to maintain native objects in Java classes, a utility C++ class is proposed. The problem of memory management when integrating Java and C++ code Recently, I had to port a library I wrote for Linux to Android. For instance, the library is aimed at implementing an…