On Aug 5, 8:17 pm, "Dmitry.Skiba" <dmitry.sk...@gmail.com> wrote: > By the way, to guarantee that non-direct buffer will not be moved be > GC one can hack up a JNI lib wich will 'pin' needed buffers for the > lifetime of an application :)
Actually, you can't. The VM has the option to pin or copy the data in the virtual heap. If you'd like to see this in action, try this (requires emulator or rooted device): % adb shell setprop dalvik.vm.checkjni true % adb shell setprop dalvik.vm.jniopts forcecopy % adb shell stop ; adb shell start The JNI "forcecopy" mode forces the VM to make a copy of data rather than pin it in place. This is less efficient due to the additional data copying, but it does allow the GC to move memory around, and will expose situations where pointers are being kept inappropriately. The forcecopy stuff also adds guard regions around the allocated blocks to check for overruns, fills the memory with a garbage pattern before freeing it to expose use-after-free, and checksums read-only stuff like String data to ensure code is not inadvertently modifying it. If you're not using direct buffers where they are required, your application will likely freak out when "forcecopy" is enabled. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---