inside native containers Cordova (PhoneGap), Electron • JavaScript & Native UI React Native • Java, Kotlin, etc. Compiles to JVM, Kotlin: JS & native • Native native, close to the metal C/C++
System specific look and feel Qt/OpenGL for custom UIs/games • OS specific calls: nope APIs more accessible from default language • App logic / special use cases: yepp Computation intensive; e.g. crypto "Business logic"; optional: networking&storage
Chrome, Firefox, Safari, and Edge • Emscriptem C/C++ Toolchain for Wasm (and js.asm) • Sandboxed • Inter-op with JavaScript • Access to browser functionality • Best support for C/C++
dependent • Programming languages translated for CPU Compilers or interpreters • CPU registers Used for data operations (, local variables, etc.) • Memory Data accessed by addresses
address) • Pointer arithmetic Use math to navigate through memory • "Safest" way to get into trouble Bad pointers, pointing to wrong address ~100x times worse than NullPointerException
is a pointer: Person* // no GC, no auto release pool, etc. // so how do we get rid of joe1? delete joe; // we have to do it ourselves Person* aPerson = findRandomPerson(); // Unclear who should delete aPerson 1) Names are products of the author’s imagination or are used fictitiously. Any resemblance to actual persons, living or dead, is entirely coincidental.
unique_ptr<Person> person = findRandomPerson(); // 1 person = findRandomPerson(); // 2 • Shared ownership with shared_ptr Allow multiple references to an object Object gets cleaned up when no more refs • Fix most pointer problems Safer & more convenient
suite – worst acronyms ever) • Best explained by example void helloRaii() { lock_guard<mutex> lock(fileMutex); ofstream file("hello.txt"); file << "Hello world"; // may ex }
are super simple Thread creation, joining, locking Atomic types • Containers (collections) List vector, HashMap unordered_map And many more • Btw, iterating over collections is quite nice: for (auto& user: userVector) { … }
methods • C API to access Java world E.g. reflection-like API to access data • Special signature for C methods • javah: creates C headers based on Java src • Pass native resources as a long handle E.g. pointers to C++ objects Java long
cast to C++ objects • JNIEnv always passed: JNI god object Create Java object, get data from J. objects • Method params: Java C type int jint String jstring Object (of any class) jobject
data Get & set fields using their name • JNI calls are somewhat expensive Must be considered when defining the API • Freeing native resources GC makes no guarantees E.g. close() and finalization; finalizer thread
kill the Java process • Catch and raise Java exception • JNI does not throw, but raise an exception Code flow continues(!) JNI method must return regularly Must check if exception already occurred
C • More convenient solutions based on JNI • JNA (Java Native Access) Define a Java interface for a native library Interface implementation by JNA Automatically converts types • Djinni by Dropbox IDL to define records, interfaces, and enums Generates C++, Java, and Objective-C sources
No equivalent for Java APIs • APIs OK for Level 14 Android Logging, Zlib, OpenGL/MAX, Bitmaps • New APIs level 26 and 27 Camera, audio, shared mem., neural networks
E.g. image data, compression in/output, etc. • jobject is not cool for C++ • C++ objects/structs not to be touched by Java • String encoded exchange? E.g. JSON/XML? • [Protocol | Flat] Buffers, Cap'n Proto "Objects as bytes" • Or a database… ;-)
lots of language updates, e.g. decomposition tuple<T1,T2,T3> fun() {return {a,b,c}; } auto [x,y,z] = fun(); // T1 x, T2 y, T3 z • Important STL upgrades Primitives: optional, any, string_view File system, parallel algorithms
{Insert YES! STRIKE! VICTORY! memes here} • Objective-C(++) simply allows C++ • Swift cannot call C++ (yet?) • Swift can all Objective-C (not ObjC++) ObjC(++) wrappers needed with ObjC protocol
Unit testing: e.g. Google Test, Catch2 • Usually tests finish before a JVM even starts • ASan (or Valgrind) to avoid memory errors Catches bad pointers etc. before it gets ugly • CI highly recommended • Safety net to keep dev productivity up