Posts

Showing posts from January, 2013

Tutorial: How to set up Smart Pointers and TR1 C++ in the Android NDK

Image
Optimus prime is a smart pointer.  Memory leaks?! He'll straight up kick you in the throat! This isn't Go Bots son! What's the point If you have ever coded in C or C++ you know you've had a memory leak some time or another. Ownership semantics are best, but sometimes those are muddy and, most of the time, the benefit of automatically reclaimed pointers far outweighs any costs (they are not much in terms of resources). What are smart pointers?   These are pointer containers/classes with reference counting and ownership semantics built in.  The easiest to understand and use is shared_ptr , which when all references are gone delete's the object from memory, and as expected calls the objects destructor (if it exists). For example if you create a raw pointer in a function (and don't store a reference to it anywhere else)  you would get a memory leak! void leak_function() { Sprite* sprite = new Sprite(); // Use sprite // After functio...

Emacs/Vim: Jump to errors for Java and C++ on Android

Any of you guys use vim or emacs to develop Android apps?  I sure do.  No substitute for a good editor.  Only problem is when I am doing NDK code and Java mixed (like so many others who develop games), the editor won't go to the errors in Java code since Ant formats the error output strangely. Well fear not folks, it is an easy fix.  I usually do all my development in a Makefile that calls ant for the Java stuff and the normal ndk-build for the JNI stuff: http://code.google.com/p/razzlegames-android-ndk-tutorial/source/browse/trunk/Makefile You simply add the -emacs option to your ant command.  I personally bind a function key to :make in vim, and have the ant command as one of the default targets.  It ends up being called like this for debug builds: ant -emacs  debug Now, with this addition, Vim and emacs will jump to all your NDK and Java errors for Android development. It's as easy as that folks!  Happy Viming!