问:
Android application crashes randomly after using JNI
I have an application which uses a C library through JNI bindings.
The same C library is used on iOS without any issues, and it was used for around 2 years already.

I've tried implementing the same library on Android, and in general, everything works as expected, but the app crashes randomly after calling the JNI code.

What I mean is that I call the library, I receive data, I do some things with the data [like update buttons on screen] and then wait for further user input.
After around 200-300ms after the call, my app crashes. By random, I mean that 1 out of 3 times it crashes. Sometimes after the first call, sometimes after 4th etc. All the time I use the same set of data, so this issue is not data specific.

Unfortunately, the errors I get are random as well. This leads me to believe, that it must be something with memory management, but damn... I have no idea how to debug it at all.

Here are few examples of the errors I get.

```<code>                                                                 ----

----- beginning of crash
06-03 13:35:37.823 6035-6035/com.mycompany.myapp A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x30384636 in tid 6035 (mycompany.myapp)

                                                             [ 06-03 13:35:37.829   182:  182 W/         ]
                                                             debuggerd: handling request: pid=6035 uid=10147 gid=10147 tid=6035
06-03 13:35:37.919 6307-6307/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
06-03 13:35:37.919 6307-6307/? A/DEBUG: Build fingerprint: 'nvidia/wx_un_do/shieldtablet:7.0/NRD90M/1928188_850.6612:user/release-keys'
06-03 13:35:37.919 6307-6307/? A/DEBUG: Revision: '0'
06-03 13:35:37.919 6307-6307/? A/DEBUG: ABI: 'arm'
06-03 13:35:37.920 6307-6307/? A/DEBUG: pid: 6035, tid: 6035, name: mycompany.myapp  >>> com.mycompany.myapp <<<
06-03 13:35:37.920 6307-6307/? A/DEBUG: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x30384636
06-03 13:35:37.920 6307-6307/? A/DEBUG:     r0 30384636  r1 00000058  r2 a49016e8  r3 00000058
06-03 13:35:37.920 6307-6307/? A/DEBUG:     r4 a480628c  r5 3038392e  r6 00000000  r7 a4806278
06-03 13:35:37.920 6307-6307/? A/DEBUG:     r8 a53532e8  r9 00000001  sl a53532dc  fp 00000001
06-03 13:35:37.920 6307-6307/? A/DEBUG:     ip a5349860  sp bea94a68  lr a532f97d  pc a5308b26  cpsr 200f0030
06-03 13:35:37.991 6307-6307/? A/DEBUG: backtrace:
06-03 13:35:37.991 6307-6307/? A/DEBUG:     #00 pc 00047b26  /system/lib/libc.so (pthread_mutex_lock+1)
06-03 13:35:37.991 6307-6307/? A/DEBUG:     #01 pc 0006e979  /system/lib/libc.so (je_tcache_bin_flush_small+144)
06-03 13:35:37.991 6307-6307/? A/DEBUG:     #02 pc 0006e88d  /system/lib/libc.so (je_tcache_event_hard+60)
06-03 13:35:37.991 6307-6307/? A/DEBUG:     #03 pc 00064d09  /system/lib/libc.so (je_calloc+776)
06-03 13:35:37.991 6307-6307/? A/DEBUG:     #04 pc 0000f94d  /data/app/com.mycompany.myapp-2/lib/arm/libmylibjni.so (roxml_malloc+64)
06-03 13:35:37.991 6307-6307/? A/DEBUG:     #05 pc 0000eeab  /data/app/com.mycompany.myapp-2/lib/arm/libmylibjni.so (roxml_get_name+502)
06-03 13:35:37.991 6307-6307/? A/DEBUG:     #06 pc 0000ef8f  /data/app/com.mycompany.myapp-2/lib/arm/libmylibjni.so (roxml_get_nodes+42)
06-03 13:35:37.991 6307-6307/? A/DEBUG:     #07 pc 0000c079  /data/app/com.mycompany.myapp-2/lib/arm/libmylibjni.so (get_attr_content+12)
06-03 13:35:37.991 6307-6307/? A/DEBUG:     #08 pc 0000c785  /data/app/com.mycompany.myapp-2/lib/arm/libmylibjni.so (get_prodcore_item+92)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #09 pc 0000c82f  /data/app/com.mycompany.myapp-2/lib/arm/libmylibjni.so (get_prodcore_items+98)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #10 pc 0000c8d3  /data/app/com.mycompany.myapp-2/lib/arm/libmylibjni.so (get_prod_prodcore+54)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #11 pc 0000a1ab  /data/app/com.mycompany.myapp-2/lib/arm/libmylibjni.so (parse_prod_file_from_buf+70)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #12 pc 0000acf7  /data/app/com.mycompany.myapp-2/lib/arm/libmylibjni.so (mylib_get_basic_info+238)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #13 pc 0000b611  /data/app/com.mycompany.myapp-2/lib/arm/libmylibjni.so (mylib_open+388)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #14 pc 0000779d  /data/app/com.mycompany.myapp-2/lib/arm/libmylibjni.so (Java_com_mycompany_mylib_mylibJNI_openmylibprod+60)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #15 pc 000ad919  /system/lib/libart.so (art_quick_generic_jni_trampoline+40)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #16 pc 000a8f41  /system/lib/libart.so (art_quick_invoke_stub_internal+64)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #17 pc 0040535d  /system/lib/libart.so (art_quick_invoke_stub+232)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #18 pc 000b0209  /system/lib/libart.so (_ZN3art9ArtMethod6InvokeEPNS_6ThreadEPjjPNS_6JValueEPKc+136)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #19 pc 001ec4eb  /system/lib/libart.so (_ZN3art11interpreter34ArtInterpreterToCompiledCodeBridgeEPNS_6ThreadEPNS_9ArtMethodEPKNS_7DexFile8CodeItemEPNS_11ShadowFrameEPNS_6JValueE+198)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #20 pc 001e6a8b  /system/lib/libart.so (_ZN3art11interpreter6DoCallILb0ELb0EEEbPNS_9ArtMethodEPNS_6ThmyappNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+478)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #21 pc 0020d1d3  /system/lib/libart.so (_ZN3art11interpreterL8DoInvokeILNS_10InvokeTypeE2ELb0ELb0EEEbPNS_6ThmyappNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+422)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #22 pc 00203259  /system/lib/libart.so (_ZN3art11interpreter17ExecuteSwitchImplILb0ELb0EEENS_6JValueEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameES2_b+12904)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #23 pc 001ca845  /system/lib/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameENS_6JValueEb+368)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #24 pc 001cf357  /system/lib/libart.so (_ZN3art11interpreter33ArtInterpreterToInterpreterBridgeEPNS_6ThreadEPKNS_7DexFile8CodeItemEPNS_11ShadowFrameEPNS_6JValueE+114)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #25 pc 001e6a6f  /system/lib/libart.so (_ZN3art11interpreter6DoCallILb0ELb0EEEbPNS_9ArtMethodEPNS_6ThmyappNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+450)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #26 pc 0020d1d3  /system/lib/libart.so (_ZN3art11interpreterL8DoInvokeILNS_10InvokeTypeE2ELb0ELb0EEEbPNS_6ThmyappNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+422)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #27 pc 00203259  /system/lib/libart.so (_ZN3art11interpreter17ExecuteSwitchImplILb0ELb0EEENS_6JValueEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameES2_b+12904)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #28 pc 001ca845  /system/lib/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameENS_6JValueEb+368)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #29 pc 001cf357  /system/lib/libart.so (_ZN3art11interpreter33ArtInterpreterToInterpreterBridgeEPNS_6ThreadEPKNS_7DexFile8CodeItemEPNS_11ShadowFrameEPNS_6JValueE+114)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #30 pc 001e6a6f  /system/lib/libart.so (_ZN3art11interpreter6DoCallILb0ELb0EEEbPNS_9ArtMethodEPNS_6ThmyappNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+450)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #31 pc 0020e809  /system/lib/libart.so (_ZN3art11interpreterL8DoInvokeILNS_10InvokeTypeE1ELb0ELb0EEEbPNS_6ThmyappNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+264)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #32 pc 002053c1  /system/lib/libart.so (_ZN3art11interpreter17ExecuteSwitchImplILb0ELb0EEENS_6JValueEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameES2_b+21456)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #33 pc 001ca845  /system/lib/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameENS_6JValueEb+368)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #34 pc 001cf357  /system/lib/libart.so (_ZN3art11interpreter33ArtInterpreterToInterpreterBridgeEPNS_6ThreadEPKNS_7DexFile8CodeItemEPNS_11ShadowFrameEPNS_6JValueE+114)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #35 pc 001e6a6f  /system/lib/libart.so (_ZN3art11interpreter6DoCallILb0ELb0EEEbPNS_9ArtMethodEPNS_6ThmyappNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+450)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #36 pc 0020e809  /system/lib/libart.so (_ZN3art11interpreterL8DoInvokeILNS_10InvokeTypeE1ELb0ELb0EEEbPNS_6ThmyappNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+264)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #37 pc 002053c1  /system/lib/libart.so (_ZN3art11interpreter17ExecuteSwitchImplILb0ELb0EEENS_6JValueEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameES2_b+21456)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #38 pc 001ca845  /system/lib/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameENS_6JValueEb+368)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #39 pc 001cf357  /system/lib/libart.so (_ZN3art11interpreter33ArtInterpreterToInterpreterBridgeEPNS_6ThreadEPKNS_7DexFile8CodeItemEPNS_11ShadowFrameEPNS_6JValueE+114)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #40 pc 001e6a6f  /system/lib/libart.so (_ZN3art11interpreter6DoCallILb0ELb0EEEbPNS_9ArtMethodEPNS_6ThmyappNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+450)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #41 pc 0020f641  /system/lib/libart.so (_ZN3art11interpreterL8DoInvokeILNS_10InvokeTypeE0ELb0ELb0EEEbPNS_6ThmyappNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+232)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #42 pc 00203ffd  /system/lib/libart.so (_ZN3art11interpreter17ExecuteSwitchImplILb0ELb0EEENS_6JValueEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameES2_b+16396)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #43 pc 001ca845  /system/lib/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameENS_6JValueEb+368)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #44 pc 001cf357  /system/lib/libart.so (_ZN3art11interpreter33ArtInterpreterToInterpreterBridgeEPNS_6ThreadEPKNS_7DexFile8CodeItemEPNS_11ShadowFrameEPNS_6JValueE+114)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #45 pc 001e6a6f  /system/lib/libart.so (_ZN3art11interpreter6DoCallILb0ELb0EEEbPNS_9ArtMethodEPNS_6ThmyappNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+450)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #46 pc 0020f033  /system/lib/libart.so (_ZN3art11interpreterL8DoInvokeILNS_10InvokeTypeE4ELb0ELb0EEEbPNS_6ThmyappNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+830)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #47 pc 00205c45  /system/lib/libart.so (_ZN3art11interpreter17ExecuteSwitchImplILb0ELb0EEENS_6JValueEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameES2_b+23636)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #48 pc 001ca845  /system/lib/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameENS_6JValueEb+368)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #49 pc 001cf357  /system/lib/libart.so (_ZN3art11interpreter33ArtInterpreterToInterpreterBridgeEPNS_6ThreadEPKNS_7DexFile8CodeItemEPNS_11ShadowFrameEPNS_6JValueE+114)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #50 pc 001e6a6f  /system/lib/libart.so (_ZN3art11interpreter6DoCallILb0ELb0EEEbPNS_9ArtMethodEPNS_6ThmyappNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+450)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #51 pc 0020d1d3  /system/lib/libart.so (_ZN3art11interpreterL8DoInvokeILNS_10InvokeTypeE2ELb0ELb0EEEbPNS_6ThmyappNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+422)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #52 pc 00203259  /system/lib/libart.so (_ZN3art11interpreter17ExecuteSwitchImplILb0ELb0EEENS_6JValueEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameES2_b+12904)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #53 pc 001ca845  /system/lib/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameENS_6JValueEb+368)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #54 pc 001cf357  /system/lib/libart.so (_ZN3art11interpreter33ArtInterpreterToInterpreterBridgeEPNS_6ThreadEPKNS_7DexFile8CodeItemEPNS_11ShadowFrameEPNS_6JValueE+114)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #55 pc 001e6a6f  /system/lib/libart.so (_ZN3art11interpreter6DoCallILb0ELb0EEEbPNS_9ArtMethodEPNS_6ThmyappNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+450)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #56 pc 0020f033  /system/lib/libart.so (_ZN3art11interpreterL8DoInvokeILNS_10InvokeTypeE4ELb0ELb0EEEbPNS_6ThmyappNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+830)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #57 pc 00205c45  /system/lib/libart.so (_ZN3art11interpreter17ExecuteSwitchImplILb0ELb0EEENS_6JValueEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameES2_b+23636)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #58 pc 001ca845  /system/lib/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameENS_6JValueEb+368)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #59 pc 001cf357  /system/lib/libart.so (_ZN3art11interpreter33ArtInterpreterToInterpreterBridgeEPNS_6ThreadEPKNS_7DexFile8CodeItemEPNS_11ShadowFrameEPNS_6JValueE+114)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #60 pc 001e6a6f  /system/lib/libart.so (_ZN3art11interpreter6DoCallILb0ELb0EEEbPNS_9ArtMethodEPNS_6ThmyappNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+450)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #61 pc 0020d1d3  /system/lib/libart.so (_ZN3art11interpreterL8DoInvokeILNS_10InvokeTypeE2ELb0ELb0EEEbPNS_6ThmyappNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+422)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #62 pc 00203259  /system/lib/libart.so (_ZN3art11interpreter17ExecuteSwitchImplILb0ELb0EEENS_6JValueEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameES2_b+12904)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #63 pc 001ca845  /system/lib/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameENS_6JValueEb+368)
</code>```

another one:

```<code>06-03 14:06:34.775 8746-8746/com.mycompany.myapp A/libc: Fatal signal 11 (SIGSEGV), code 2, fault addr 0x3438379e in tid 8746 (mycompany.myapp)

                                                             [ 06-03 14:06:34.776   182:  182 W/         ]
                                                             debuggerd: handling request: pid=8746 uid=10147 gid=10147 tid=8746
06-03 14:06:34.842 9224-9224/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
06-03 14:06:34.843 9224-9224/? A/DEBUG: Build fingerprint: 'nvidia/wx_un_do/shieldtablet:7.0/NRD90M/1928188_850.6612:user/release-keys'
06-03 14:06:34.843 9224-9224/? A/DEBUG: Revision: '0'
06-03 14:06:34.843 9224-9224/? A/DEBUG: ABI: 'arm'
06-03 14:06:34.843 9224-9224/? A/DEBUG: pid: 8746, tid: 8746, name: mycompany.myapp  >>> com.mycompany.myapp <<<
06-03 14:06:34.843 9224-9224/? A/DEBUG: signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 0x3438379e
06-03 14:06:34.843 9224-9224/? A/DEBUG:     r0 3438379e  r1 00000058  r2 a4900e50  r3 00000058
06-03 14:06:34.843 9224-9224/? A/DEBUG:     r4 a4806034  r5 3438332e  r6 00000000  r7 a4806020
06-03 14:06:34.843 9224-9224/? A/DEBUG:     r8 a53532e8  r9 00000004  sl a53532dc  fp 00000004
06-03 14:06:34.843 9224-9224/? A/DEBUG:     ip a5349860  sp bea948c8  lr a532f97d  pc a5308b26  cpsr 20070030
06-03 14:06:34.945 9224-9224/? A/DEBUG: backtrace:
06-03 14:06:34.945 9224-9224/? A/DEBUG:     #00 pc 00047b26  /system/lib/libc.so (pthread_mutex_lock+1)
06-03 14:06:34.945 9224-9224/? A/DEBUG:     #01 pc 0006e979  /system/lib/libc.so (je_tcache_bin_flush_small+144)
06-03 14:06:34.945 9224-9224/? A/DEBUG:     #02 pc 00066f09  /system/lib/libc.so (ifree+432)
06-03 14:06:34.945 9224-9224/? A/DEBUG:     #03 pc 000671eb  /system/lib/libc.so (je_free+74)
06-03 14:06:34.945 9224-9224/? A/DEBUG:     #04 pc 00010c2f  /data/app/com.mycompany.myapp-2/lib/arm/libmylibjni.so (roxml_del_from_pool+72)
</code>```

and yet another:

```<code>06-03 21:23:53.136 19575-19829/com.mycompany.myapp A/libc: Fatal signal 11 (SIGSEGV), code 2, fault addr 0x3438480a in tid 19829 (RenderThread)

                                                               [ 06-03 21:23:53.137   182:  182 W/         ]
                                                               debuggerd: handling request: pid=19575 uid=10147 gid=10147 tid=19829
06-03 21:23:53.446 19995-19995/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
06-03 21:23:53.446 19995-19995/? A/DEBUG: Build fingerprint: 'nvidia/wx_un_do/shieldtablet:7.0/NRD90M/1928188_850.6612:user/release-keys'
06-03 21:23:53.447 19995-19995/? A/DEBUG: Revision: '0'
06-03 21:23:53.447 19995-19995/? A/DEBUG: ABI: 'arm'
06-03 21:23:53.448 19995-19995/? A/DEBUG: pid: 19575, tid: 19829, name: RenderThread  >>> com.mycompany.myapp <<<
06-03 21:23:53.448 19995-19995/? A/DEBUG: signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 0x3438480a
06-03 21:23:53.448 19995-19995/? A/DEBUG:     r0 3438392e  r1 8b8fda20  r2 00000001  r3 00000000
06-03 21:23:53.449 19995-19995/? A/DEBUG:     r4 a483aa00  r5 8b8fd3ec  r6 98356000  r7 00000002
06-03 21:23:53.449 19995-19995/? A/DEBUG:     r8 00000001  r9 00000000  sl a4863a84  fp a4863a80
06-03 21:23:53.449 19995-19995/? A/DEBUG:     ip a71ecf18  sp 8b8fd330  lr 98305edf  pc 98305eec  cpsr 00000030
06-03 21:23:53.481 19995-19995/? A/DEBUG: backtrace:
06-03 21:23:53.481 19995-19995/? A/DEBUG:     #00 pc 0000deec  /system/vendor/lib/egl/libEGL_tegra.so
06-03 21:23:53.481 19995-19995/? A/DEBUG:     #01 pc 00013805  /system/vendor/lib/egl/libEGL_tegra.so (eglGetError+4)
06-03 21:23:53.481 19995-19995/? A/DEBUG:     #02 pc 0000c071  /system/lib/libEGL.so (eglGetError+20)
06-03 21:23:53.481 19995-19995/? A/DEBUG:     #03 pc 0000b93f  /system/lib/libEGL.so (eglQuerySurface+22)
06-03 21:23:53.481 19995-19995/? A/DEBUG:     #04 pc 00025963  /system/lib/libhwui.so
06-03 21:23:53.482 19995-19995/? A/DEBUG:     #05 pc 0002311f  /system/lib/libhwui.so
06-03 21:23:53.482 19995-19995/? A/DEBUG:     #06 pc 00024d6b  /system/lib/libhwui.so
06-03 21:23:53.482 19995-19995/? A/DEBUG:     #07 pc 00028181  /system/lib/libhwui.so (_ZN7android10uirenderer12renderthread12RenderThread10threadLoopEv+80)
06-03 21:23:53.482 19995-19995/? A/DEBUG:     #08 pc 0000f155  /system/lib/libutils.so (_ZN7android6Thread11_threadLoopEPv+144)
06-03 21:23:53.482 19995-19995/? A/DEBUG:     #09 pc 00065e75  /system/lib/libandroid_runtime.so (_ZN7android14AndroidRuntime15javaThreadShellEPv+80)
06-03 21:23:53.482 19995-19995/? A/DEBUG:     #10 pc 00047543  /system/lib/libc.so (_ZL15__pthread_startPv+22)
06-03 21:23:53.482 19995-19995/? A/DEBUG:     #11 pc 0001a115  /system/lib/libc.so (__start_thread+6)
</code>```

I have to admit, I hate this kind of errors. I have no clue where to look for solutions.

Now a bit about the library:

it takes a zip file, unpacks an xml file out of it and parses data from the xml into a struct which then is used to generate an object with all of that data.

That's basically it.
In the JNI class I hold the value of JNIEnv because there is a scenario where I have to call java class from C, but not in this case. The calls I make are limited to the description I gave above.

Also, this happens very often on first call so I doubt it has anything to do with that.

Is there anything else I could provide to make it possible to determine the cause of the crashes?

I am a bit fed up with the issue, if it was up to me I would just rewrite the lib in java, but the whole idea of getting the C lib was to have a single code running on all platforms.

I will be grateful for any help.

EDIT
I was able to remove a lot of the code from calls to identify the simplest possible way for my app to crash.
Now I only have one function which when called will [randomly] crashe the app, and when not called, will never do this.

Here's the JNI code i call, quite simple. Maybe my bug is much simpler then I though.

```<code>jlong Java_com_mycompany_product_ProdJNI_openProdBook(JNIEnv* env, jobject this, jstring jprname) {

    // set the jvm variable so other C threads can access java virtual machine
    (*env)->GetJavaVM(env, &jvm);

    const char *prodname = (*env)->GetStringUTFChars(env, jprname, NULL);
    unsigned long ret = product_open(prodname);
    (*env)->ReleaseStringUTFChars(env, jprname, prodname);
    return ret;
}
</code>```

答:
Question is, why do you call GetJavaVM at all? It make sense in case you call Java from C. Take a look here:

http://jnicookbook.owsiak.org/recipe-no-027/

I'd make you JNI code following way:

```<code>jlong Java_com_mycompany_product_ProdJNI_openProdBook(JNIEnv* env, jobject this, jstring jprname) {

    const char *prodname = (*env)->GetStringUTFChars(env, jprname, NULL);
    unsigned long ret = product_open(prodname);
    (*env)->ReleaseStringUTFChars(env, jprname, prodname);
    return ret;
}
</code>```

It should work without any issues.

You can test it here:

http://jnicookbook.owsiak.org/recipe-No-009/

where supper simple code passes Java string between Java and C.

Have fun with JNI!

Body:
I have an application which uses a C library through JNI bindings.
The same C library is used on iOS without any issues, and it was used for around 2 years already.

I've tried implementing the same library on Android, and in general, everything works as expected, but the app crashes randomly after calling the JNI code.

What I mean is that I call the library, I receive data, I do some things with the data [like update buttons on screen] and then wait for further user input.
After around 200-300ms after the call, my app crashes. By random, I mean that 1 out of 3 times it crashes. Sometimes after the first call, sometimes after 4th etc. All the time I use the same set of data, so this issue is not data specific.

Unfortunately, the errors I get are random as well. This leads me to believe, that it must be something with memory management, but damn... I have no idea how to debug it at all.

Here are few examples of the errors I get.

                                                                 ----

----- beginning of crash
06-03 13:35:37.823 6035-6035/com.mycompany.myapp A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x30384636 in tid 6035 (mycompany.myapp)

                                                             [ 06-03 13:35:37.829   182:  182 W/         ]
                                                             debuggerd: handling request: pid=6035 uid=10147 gid=10147 tid=6035
06-03 13:35:37.919 6307-6307/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
06-03 13:35:37.919 6307-6307/? A/DEBUG: Build fingerprint: 'nvidia/wx_un_do/shieldtablet:7.0/NRD90M/1928188_850.6612:user/release-keys'
06-03 13:35:37.919 6307-6307/? A/DEBUG: Revision: '0'
06-03 13:35:37.919 6307-6307/? A/DEBUG: ABI: 'arm'
06-03 13:35:37.920 6307-6307/? A/DEBUG: pid: 6035, tid: 6035, name: mycompany.myapp  >>> com.mycompany.myapp <<<
06-03 13:35:37.920 6307-6307/? A/DEBUG: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x30384636
06-03 13:35:37.920 6307-6307/? A/DEBUG:     r0 30384636  r1 00000058  r2 a49016e8  r3 00000058
06-03 13:35:37.920 6307-6307/? A/DEBUG:     r4 a480628c  r5 3038392e  r6 00000000  r7 a4806278
06-03 13:35:37.920 6307-6307/? A/DEBUG:     r8 a53532e8  r9 00000001  sl a53532dc  fp 00000001
06-03 13:35:37.920 6307-6307/? A/DEBUG:     ip a5349860  sp bea94a68  lr a532f97d  pc a5308b26  cpsr 200f0030
06-03 13:35:37.991 6307-6307/? A/DEBUG: backtrace:
06-03 13:35:37.991 6307-6307/? A/DEBUG:     #00 pc 00047b26  /system/lib/libc.so (pthread_mutex_lock+1)
06-03 13:35:37.991 6307-6307/? A/DEBUG:     #01 pc 0006e979  /system/lib/libc.so (je_tcache_bin_flush_small+144)
06-03 13:35:37.991 6307-6307/? A/DEBUG:     #02 pc 0006e88d  /system/lib/libc.so (je_tcache_event_hard+60)
06-03 13:35:37.991 6307-6307/? A/DEBUG:     #03 pc 00064d09  /system/lib/libc.so (je_calloc+776)
06-03 13:35:37.991 6307-6307/? A/DEBUG:     #04 pc 0000f94d  /data/app/com.mycompany.myapp-2/lib/arm/libmylibjni.so (roxml_malloc+64)
06-03 13:35:37.991 6307-6307/? A/DEBUG:     #05 pc 0000eeab  /data/app/com.mycompany.myapp-2/lib/arm/libmylibjni.so (roxml_get_name+502)
06-03 13:35:37.991 6307-6307/? A/DEBUG:     #06 pc 0000ef8f  /data/app/com.mycompany.myapp-2/lib/arm/libmylibjni.so (roxml_get_nodes+42)
06-03 13:35:37.991 6307-6307/? A/DEBUG:     #07 pc 0000c079  /data/app/com.mycompany.myapp-2/lib/arm/libmylibjni.so (get_attr_content+12)
06-03 13:35:37.991 6307-6307/? A/DEBUG:     #08 pc 0000c785  /data/app/com.mycompany.myapp-2/lib/arm/libmylibjni.so (get_prodcore_item+92)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #09 pc 0000c82f  /data/app/com.mycompany.myapp-2/lib/arm/libmylibjni.so (get_prodcore_items+98)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #10 pc 0000c8d3  /data/app/com.mycompany.myapp-2/lib/arm/libmylibjni.so (get_prod_prodcore+54)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #11 pc 0000a1ab  /data/app/com.mycompany.myapp-2/lib/arm/libmylibjni.so (parse_prod_file_from_buf+70)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #12 pc 0000acf7  /data/app/com.mycompany.myapp-2/lib/arm/libmylibjni.so (mylib_get_basic_info+238)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #13 pc 0000b611  /data/app/com.mycompany.myapp-2/lib/arm/libmylibjni.so (mylib_open+388)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #14 pc 0000779d  /data/app/com.mycompany.myapp-2/lib/arm/libmylibjni.so (Java_com_mycompany_mylib_mylibJNI_openmylibprod+60)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #15 pc 000ad919  /system/lib/libart.so (art_quick_generic_jni_trampoline+40)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #16 pc 000a8f41  /system/lib/libart.so (art_quick_invoke_stub_internal+64)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #17 pc 0040535d  /system/lib/libart.so (art_quick_invoke_stub+232)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #18 pc 000b0209  /system/lib/libart.so (_ZN3art9ArtMethod6InvokeEPNS_6ThreadEPjjPNS_6JValueEPKc+136)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #19 pc 001ec4eb  /system/lib/libart.so (_ZN3art11interpreter34ArtInterpreterToCompiledCodeBridgeEPNS_6ThreadEPNS_9ArtMethodEPKNS_7DexFile8CodeItemEPNS_11ShadowFrameEPNS_6JValueE+198)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #20 pc 001e6a8b  /system/lib/libart.so (_ZN3art11interpreter6DoCallILb0ELb0EEEbPNS_9ArtMethodEPNS_6ThmyappNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+478)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #21 pc 0020d1d3  /system/lib/libart.so (_ZN3art11interpreterL8DoInvokeILNS_10InvokeTypeE2ELb0ELb0EEEbPNS_6ThmyappNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+422)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #22 pc 00203259  /system/lib/libart.so (_ZN3art11interpreter17ExecuteSwitchImplILb0ELb0EEENS_6JValueEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameES2_b+12904)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #23 pc 001ca845  /system/lib/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameENS_6JValueEb+368)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #24 pc 001cf357  /system/lib/libart.so (_ZN3art11interpreter33ArtInterpreterToInterpreterBridgeEPNS_6ThreadEPKNS_7DexFile8CodeItemEPNS_11ShadowFrameEPNS_6JValueE+114)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #25 pc 001e6a6f  /system/lib/libart.so (_ZN3art11interpreter6DoCallILb0ELb0EEEbPNS_9ArtMethodEPNS_6ThmyappNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+450)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #26 pc 0020d1d3  /system/lib/libart.so (_ZN3art11interpreterL8DoInvokeILNS_10InvokeTypeE2ELb0ELb0EEEbPNS_6ThmyappNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+422)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #27 pc 00203259  /system/lib/libart.so (_ZN3art11interpreter17ExecuteSwitchImplILb0ELb0EEENS_6JValueEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameES2_b+12904)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #28 pc 001ca845  /system/lib/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameENS_6JValueEb+368)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #29 pc 001cf357  /system/lib/libart.so (_ZN3art11interpreter33ArtInterpreterToInterpreterBridgeEPNS_6ThreadEPKNS_7DexFile8CodeItemEPNS_11ShadowFrameEPNS_6JValueE+114)
06-03 13:35:37.992 6307-6307/? A/DEBUG:     #30 pc 001e6a6f  /system/lib/libart.so (_ZN3art11interpreter6DoCallILb0ELb0EEEbPNS_9ArtMethodEPNS_6ThmyappNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+450)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #31 pc 0020e809  /system/lib/libart.so (_ZN3art11interpreterL8DoInvokeILNS_10InvokeTypeE1ELb0ELb0EEEbPNS_6ThmyappNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+264)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #32 pc 002053c1  /system/lib/libart.so (_ZN3art11interpreter17ExecuteSwitchImplILb0ELb0EEENS_6JValueEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameES2_b+21456)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #33 pc 001ca845  /system/lib/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameENS_6JValueEb+368)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #34 pc 001cf357  /system/lib/libart.so (_ZN3art11interpreter33ArtInterpreterToInterpreterBridgeEPNS_6ThreadEPKNS_7DexFile8CodeItemEPNS_11ShadowFrameEPNS_6JValueE+114)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #35 pc 001e6a6f  /system/lib/libart.so (_ZN3art11interpreter6DoCallILb0ELb0EEEbPNS_9ArtMethodEPNS_6ThmyappNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+450)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #36 pc 0020e809  /system/lib/libart.so (_ZN3art11interpreterL8DoInvokeILNS_10InvokeTypeE1ELb0ELb0EEEbPNS_6ThmyappNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+264)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #37 pc 002053c1  /system/lib/libart.so (_ZN3art11interpreter17ExecuteSwitchImplILb0ELb0EEENS_6JValueEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameES2_b+21456)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #38 pc 001ca845  /system/lib/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameENS_6JValueEb+368)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #39 pc 001cf357  /system/lib/libart.so (_ZN3art11interpreter33ArtInterpreterToInterpreterBridgeEPNS_6ThreadEPKNS_7DexFile8CodeItemEPNS_11ShadowFrameEPNS_6JValueE+114)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #40 pc 001e6a6f  /system/lib/libart.so (_ZN3art11interpreter6DoCallILb0ELb0EEEbPNS_9ArtMethodEPNS_6ThmyappNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+450)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #41 pc 0020f641  /system/lib/libart.so (_ZN3art11interpreterL8DoInvokeILNS_10InvokeTypeE0ELb0ELb0EEEbPNS_6ThmyappNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+232)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #42 pc 00203ffd  /system/lib/libart.so (_ZN3art11interpreter17ExecuteSwitchImplILb0ELb0EEENS_6JValueEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameES2_b+16396)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #43 pc 001ca845  /system/lib/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameENS_6JValueEb+368)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #44 pc 001cf357  /system/lib/libart.so (_ZN3art11interpreter33ArtInterpreterToInterpreterBridgeEPNS_6ThreadEPKNS_7DexFile8CodeItemEPNS_11ShadowFrameEPNS_6JValueE+114)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #45 pc 001e6a6f  /system/lib/libart.so (_ZN3art11interpreter6DoCallILb0ELb0EEEbPNS_9ArtMethodEPNS_6ThmyappNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+450)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #46 pc 0020f033  /system/lib/libart.so (_ZN3art11interpreterL8DoInvokeILNS_10InvokeTypeE4ELb0ELb0EEEbPNS_6ThmyappNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+830)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #47 pc 00205c45  /system/lib/libart.so (_ZN3art11interpreter17ExecuteSwitchImplILb0ELb0EEENS_6JValueEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameES2_b+23636)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #48 pc 001ca845  /system/lib/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameENS_6JValueEb+368)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #49 pc 001cf357  /system/lib/libart.so (_ZN3art11interpreter33ArtInterpreterToInterpreterBridgeEPNS_6ThreadEPKNS_7DexFile8CodeItemEPNS_11ShadowFrameEPNS_6JValueE+114)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #50 pc 001e6a6f  /system/lib/libart.so (_ZN3art11interpreter6DoCallILb0ELb0EEEbPNS_9ArtMethodEPNS_6ThmyappNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+450)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #51 pc 0020d1d3  /system/lib/libart.so (_ZN3art11interpreterL8DoInvokeILNS_10InvokeTypeE2ELb0ELb0EEEbPNS_6ThmyappNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+422)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #52 pc 00203259  /system/lib/libart.so (_ZN3art11interpreter17ExecuteSwitchImplILb0ELb0EEENS_6JValueEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameES2_b+12904)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #53 pc 001ca845  /system/lib/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameENS_6JValueEb+368)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #54 pc 001cf357  /system/lib/libart.so (_ZN3art11interpreter33ArtInterpreterToInterpreterBridgeEPNS_6ThreadEPKNS_7DexFile8CodeItemEPNS_11ShadowFrameEPNS_6JValueE+114)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #55 pc 001e6a6f  /system/lib/libart.so (_ZN3art11interpreter6DoCallILb0ELb0EEEbPNS_9ArtMethodEPNS_6ThmyappNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+450)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #56 pc 0020f033  /system/lib/libart.so (_ZN3art11interpreterL8DoInvokeILNS_10InvokeTypeE4ELb0ELb0EEEbPNS_6ThmyappNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+830)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #57 pc 00205c45  /system/lib/libart.so (_ZN3art11interpreter17ExecuteSwitchImplILb0ELb0EEENS_6JValueEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameES2_b+23636)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #58 pc 001ca845  /system/lib/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameENS_6JValueEb+368)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #59 pc 001cf357  /system/lib/libart.so (_ZN3art11interpreter33ArtInterpreterToInterpreterBridgeEPNS_6ThreadEPKNS_7DexFile8CodeItemEPNS_11ShadowFrameEPNS_6JValueE+114)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #60 pc 001e6a6f  /system/lib/libart.so (_ZN3art11interpreter6DoCallILb0ELb0EEEbPNS_9ArtMethodEPNS_6ThmyappNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+450)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #61 pc 0020d1d3  /system/lib/libart.so (_ZN3art11interpreterL8DoInvokeILNS_10InvokeTypeE2ELb0ELb0EEEbPNS_6ThmyappNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+422)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #62 pc 00203259  /system/lib/libart.so (_ZN3art11interpreter17ExecuteSwitchImplILb0ELb0EEENS_6JValueEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameES2_b+12904)
06-03 13:35:37.993 6307-6307/? A/DEBUG:     #63 pc 001ca845  /system/lib/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadEPKNS_7DexFile8CodeItemERNS_11ShadowFrameENS_6JValueEb+368)

another one:

06-03 14:06:34.775 8746-8746/com.mycompany.myapp A/libc: Fatal signal 11 (SIGSEGV), code 2, fault addr 0x3438379e in tid 8746 (mycompany.myapp)

                                                             [ 06-03 14:06:34.776   182:  182 W/         ]
                                                             debuggerd: handling request: pid=8746 uid=10147 gid=10147 tid=8746
06-03 14:06:34.842 9224-9224/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
06-03 14:06:34.843 9224-9224/? A/DEBUG: Build fingerprint: 'nvidia/wx_un_do/shieldtablet:7.0/NRD90M/1928188_850.6612:user/release-keys'
06-03 14:06:34.843 9224-9224/? A/DEBUG: Revision: '0'
06-03 14:06:34.843 9224-9224/? A/DEBUG: ABI: 'arm'
06-03 14:06:34.843 9224-9224/? A/DEBUG: pid: 8746, tid: 8746, name: mycompany.myapp  >>> com.mycompany.myapp <<<
06-03 14:06:34.843 9224-9224/? A/DEBUG: signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 0x3438379e
06-03 14:06:34.843 9224-9224/? A/DEBUG:     r0 3438379e  r1 00000058  r2 a4900e50  r3 00000058
06-03 14:06:34.843 9224-9224/? A/DEBUG:     r4 a4806034  r5 3438332e  r6 00000000  r7 a4806020
06-03 14:06:34.843 9224-9224/? A/DEBUG:     r8 a53532e8  r9 00000004  sl a53532dc  fp 00000004
06-03 14:06:34.843 9224-9224/? A/DEBUG:     ip a5349860  sp bea948c8  lr a532f97d  pc a5308b26  cpsr 20070030
06-03 14:06:34.945 9224-9224/? A/DEBUG: backtrace:
06-03 14:06:34.945 9224-9224/? A/DEBUG:     #00 pc 00047b26  /system/lib/libc.so (pthread_mutex_lock+1)
06-03 14:06:34.945 9224-9224/? A/DEBUG:     #01 pc 0006e979  /system/lib/libc.so (je_tcache_bin_flush_small+144)
06-03 14:06:34.945 9224-9224/? A/DEBUG:     #02 pc 00066f09  /system/lib/libc.so (ifree+432)
06-03 14:06:34.945 9224-9224/? A/DEBUG:     #03 pc 000671eb  /system/lib/libc.so (je_free+74)
06-03 14:06:34.945 9224-9224/? A/DEBUG:     #04 pc 00010c2f  /data/app/com.mycompany.myapp-2/lib/arm/libmylibjni.so (roxml_del_from_pool+72)

and yet another:

06-03 21:23:53.136 19575-19829/com.mycompany.myapp A/libc: Fatal signal 11 (SIGSEGV), code 2, fault addr 0x3438480a in tid 19829 (RenderThread)

                                                               [ 06-03 21:23:53.137   182:  182 W/         ]
                                                               debuggerd: handling request: pid=19575 uid=10147 gid=10147 tid=19829
06-03 21:23:53.446 19995-19995/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
06-03 21:23:53.446 19995-19995/? A/DEBUG: Build fingerprint: 'nvidia/wx_un_do/shieldtablet:7.0/NRD90M/1928188_850.6612:user/release-keys'
06-03 21:23:53.447 19995-19995/? A/DEBUG: Revision: '0'
06-03 21:23:53.447 19995-19995/? A/DEBUG: ABI: 'arm'
06-03 21:23:53.448 19995-19995/? A/DEBUG: pid: 19575, tid: 19829, name: RenderThread  >>> com.mycompany.myapp <<<
06-03 21:23:53.448 19995-19995/? A/DEBUG: signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 0x3438480a
06-03 21:23:53.448 19995-19995/? A/DEBUG:     r0 3438392e  r1 8b8fda20  r2 00000001  r3 00000000
06-03 21:23:53.449 19995-19995/? A/DEBUG:     r4 a483aa00  r5 8b8fd3ec  r6 98356000  r7 00000002
06-03 21:23:53.449 19995-19995/? A/DEBUG:     r8 00000001  r9 00000000  sl a4863a84  fp a4863a80
06-03 21:23:53.449 19995-19995/? A/DEBUG:     ip a71ecf18  sp 8b8fd330  lr 98305edf  pc 98305eec  cpsr 00000030
06-03 21:23:53.481 19995-19995/? A/DEBUG: backtrace:
06-03 21:23:53.481 19995-19995/? A/DEBUG:     #00 pc 0000deec  /system/vendor/lib/egl/libEGL_tegra.so
06-03 21:23:53.481 19995-19995/? A/DEBUG:     #01 pc 00013805  /system/vendor/lib/egl/libEGL_tegra.so (eglGetError+4)
06-03 21:23:53.481 19995-19995/? A/DEBUG:     #02 pc 0000c071  /system/lib/libEGL.so (eglGetError+20)
06-03 21:23:53.481 19995-19995/? A/DEBUG:     #03 pc 0000b93f  /system/lib/libEGL.so (eglQuerySurface+22)
06-03 21:23:53.481 19995-19995/? A/DEBUG:     #04 pc 00025963  /system/lib/libhwui.so
06-03 21:23:53.482 19995-19995/? A/DEBUG:     #05 pc 0002311f  /system/lib/libhwui.so
06-03 21:23:53.482 19995-19995/? A/DEBUG:     #06 pc 00024d6b  /system/lib/libhwui.so
06-03 21:23:53.482 19995-19995/? A/DEBUG:     #07 pc 00028181  /system/lib/libhwui.so (_ZN7android10uirenderer12renderthread12RenderThread10threadLoopEv+80)
06-03 21:23:53.482 19995-19995/? A/DEBUG:     #08 pc 0000f155  /system/lib/libutils.so (_ZN7android6Thread11_threadLoopEPv+144)
06-03 21:23:53.482 19995-19995/? A/DEBUG:     #09 pc 00065e75  /system/lib/libandroid_runtime.so (_ZN7android14AndroidRuntime15javaThreadShellEPv+80)
06-03 21:23:53.482 19995-19995/? A/DEBUG:     #10 pc 00047543  /system/lib/libc.so (_ZL15__pthread_startPv+22)
06-03 21:23:53.482 19995-19995/? A/DEBUG:     #11 pc 0001a115  /system/lib/libc.so (__start_thread+6)

I have to admit, I hate this kind of errors. I have no clue where to look for solutions.

Now a bit about the library:

it takes a zip file, unpacks an xml file out of it and parses data from the xml into a struct which then is used to generate an object with all of that data.

That's basically it.
In the JNI class I hold the value of JNIEnv because there is a scenario where I have to call java class from C, but not in this case. The calls I make are limited to the description I gave above.

Also, this happens very often on first call so I doubt it has anything to do with that.

Is there anything else I could provide to make it possible to determine the cause of the crashes?

I am a bit fed up with the issue, if it was up to me I would just rewrite the lib in java, but the whole idea of getting the C lib was to have a single code running on all platforms.

I will be grateful for any help.

EDIT
I was able to remove a lot of the code from calls to identify the simplest possible way for my app to crash.
Now I only have one function which when called will [randomly] crashe the app, and when not called, will never do this.

Here's the JNI code i call, quite simple. Maybe my bug is much simpler then I though.

jlong Java_com_mycompany_product_ProdJNI_openProdBook(JNIEnv* env, jobject this, jstring jprname) {

    // set the jvm variable so other C threads can access java virtual machine
    (*env)->GetJavaVM(env, &jvm);

    const char *prodname = (*env)->GetStringUTFChars(env, jprname, NULL);
    unsigned long ret = product_open(prodname);
    (*env)->ReleaseStringUTFChars(env, jprname, prodname);
    return ret;
}

Body:
Question is, why do you call GetJavaVM at all? It make sense in case you call Java from C. Take a look here:

http://jnicookbook.owsiak.org/recipe-no-027/

I'd make you JNI code following way:

jlong Java_com_mycompany_product_ProdJNI_openProdBook(JNIEnv* env, jobject this, jstring jprname) {

    const char *prodname = (*env)->GetStringUTFChars(env, jprname, NULL);
    unsigned long ret = product_open(prodname);
    (*env)->ReleaseStringUTFChars(env, jprname, prodname);
    return ret;
}

It should work without any issues.

You can test it here:

http://jnicookbook.owsiak.org/recipe-No-009/

where supper simple code passes Java string between Java and C.

Have fun with JNI!


来源: stackexchange

问:
Microsoft.ace.oledb.12.0 provider is not registered while connecting to access database to my website
I'm using windows 64 and I got Microsoft office 2016 64 bit and when i try to connect to the database I get the error:

the microsoft.ace.oledb.12.0 provider is not registered on the local machine

I also tried to enable 32-bit application in the internet information services (ISS) Application's pool just in case, but that didn't work either.

答:
Try installing Access Database Engine for Office

https://www.microsoft.com/en-us/download/details.aspx?id=54920

ContentLicense: CC BY-SA 3.0


答:
You could use bracket notation as property accessor for the first part and then dot notation for the Title.

```<code>my['-KlmA9TB_CifHma9bWxn'].Title
</code>```

Title: How to get the property value of object with special character

Body:
You could use bracket notation as property accessor for the first part and then dot notation for the Title.

my['-KlmA9TB_CifHma9bWxn'].Title


问:
ASP.NET 2.0 - Validating nonvisible Controls on the same page?
I have an application that uses RequiredFieldValidator controls with a ValidationSummary and once a "Finish" button is clicked all the fields are validated. This page has several different parts of it that are made visible or invisible and I noticed that the Validators only activate for visible controls and ignore the invisible ones. This is a useful functionality that is utilized by my program.

however....

I have a need to validate controls that aren't visible since I am splitting up parts of one long page into segments. So I was wondering if there is a way to manually force visible = false validation controls (or ones that are part of an invisible table, etc) to be validated on Page.IsValid, without having to make them visible again?

Thanks in Advance!

P.S. I tried using the ValidationGroup property to see if that would catch them but it didn't.

答:
In response to the 2nd comment to Mike Comstock's post (I don't have enough reputation to comment yet :( )...

to remove the spacing try:

```<code>.invisible { visibility:hidden; display:none; }
</code>```

ContentLicense: CC BY-SA 2.5

Body:
In response to the 2nd comment to Mike Comstock's post (I don't have enough reputation to comment yet :( )...

to remove the spacing try:

.invisible { visibility:hidden; display:none; }

OwnerDisplayName: Trev


问:
"MyBase" and "MyClass" Usage in VB.NET
In what scenarios would one use the MyBase and MyClass keywords in VB.NET?

答:
Regarding the usage of MyClass, there is a very minor speed improvement to be had if you're using MyClass inside of a leaf class (NotInheritable class).  Specifically, if there is some method that exists in a parent class and is not overridden OR exists as an override in the leaf class, then using MyClass instead of Me causes a call opcode to be used instead of callvirt.

MyBase, which also emits the call opcode, isn't applicable in this case where you want the method to be invoked regardless if it's implemented/overridden in the leaf or existing only in the parent.  I.e., you're maintaining a form of style consistency among a large number of similar objects.

And when I say "speed improvement", I'm talking a paltry ~5ms out of 100,000 runs on a low-end development server running in 32bit mode, on a string-parsing function.  Or to state it another way, the faster the machine, the smaller this difference is going to be.  But, I wanted to put it out there.

Title: "MyBase" and "MyClass" Usage in VB.NET


问:
error while installing graphlab in ubuntu
I am getting the following error while installing graphlab in ubuntu 14.04. I already spent lot of time to solve this problem by googling it. can any one help me to solve this prblem.

Error:

```<code>ramy@ramy-Aspire-4739Z:~$ sudo pip install --upgrade https://get.graphlab.com/GraphLab-Create/2.1/mohangtrichy@gmail.com/<KEY>/GraphLab-Create-License.tar.gz
Downloading/unpacking https://get.graphlab.com/GraphLab-Create/2.1/mohangtrichy@gmail.com/<KEY>/GraphLab-Create-License.tar.gz
Cleaning up...
Exception:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 122, in main
    status = self.run(options, args)
  File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 278, in run
    requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
  File "/usr/lib/python2.7/dist-packages/pip/req.py", line 1198, in prepare_files
    do_download,
  File "/usr/lib/python2.7/dist-packages/pip/req.py", line 1376, in unpack_url
    self.session,
  File "/usr/lib/python2.7/dist-packages/pip/download.py", line 546, in unpack_http_url
    resp = session.get(target_url, stream=True)
  File "/usr/share/python-wheels/requests-2.2.1-py2.py3-none-any.whl/requests/sessions.py", line 467, in get
    return self.request('GET', url, **kwargs)
  File "/usr/lib/python2.7/dist-packages/pip/download.py", line 237, in request
    return super(PipSession, self).request(method, url, *args, **kwargs)
  File "/usr/share/python-wheels/requests-2.2.1-py2.py3-none-any.whl/requests/sessions.py", line 455, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/share/python-wheels/requests-2.2.1-py2.py3-none-any.whl/requests/sessions.py", line 558, in send
    r = adapter.send(request, **kwargs)
  File "/usr/share/python-wheels/requests-2.2.1-py2.py3-none-any.whl/requests/adapters.py", line 385, in send
    raise SSLError(e)
SSLError: [Errno 1] _ssl.c:510: error:14077438:SSL    routines:SSL23_GET_SERVER_HELLO:tlsv1 alert internal error

Storing debug log for failure in /home/ramy/.pip/pip.log
ramy@ramy-Aspire-4739Z:~$
</code>```

答:
Requests can verify SSL certificates for HTTPS requests, just like a
  web browser. To check a host’s SSL certificate, you can use the verify
  argument:

And if you want to avoid the SSLError you can find the requests part and change verify to False:

```<code>requests.get('https://google.com', verify=False)
</code>```

Another way reinstall certifi module:

```<code>sudo pip uninstall -y certifi
sudo pip install certifi==2015.04.28
</code>```

Have a look at these questions:

Python Requests throwing up SSLError

SSLError: bad handshake, Python requests

Body:
I am getting the following error while installing graphlab in ubuntu 14.04. I already spent lot of time to solve this problem by googling it. can any one help me to solve this prblem.

Error:

ramy@ramy-Aspire-4739Z:~$ sudo pip install --upgrade https://get.graphlab.com/GraphLab-Create/2.1/mohangtrichy@gmail.com/<KEY>/GraphLab-Create-License.tar.gz
Downloading/unpacking https://get.graphlab.com/GraphLab-Create/2.1/mohangtrichy@gmail.com/<KEY>/GraphLab-Create-License.tar.gz
Cleaning up...
Exception:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 122, in main
    status = self.run(options, args)
  File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 278, in run
    requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
  File "/usr/lib/python2.7/dist-packages/pip/req.py", line 1198, in prepare_files
    do_download,
  File "/usr/lib/python2.7/dist-packages/pip/req.py", line 1376, in unpack_url
    self.session,
  File "/usr/lib/python2.7/dist-packages/pip/download.py", line 546, in unpack_http_url
    resp = session.get(target_url, stream=True)
  File "/usr/share/python-wheels/requests-2.2.1-py2.py3-none-any.whl/requests/sessions.py", line 467, in get
    return self.request('GET', url, **kwargs)
  File "/usr/lib/python2.7/dist-packages/pip/download.py", line 237, in request
    return super(PipSession, self).request(method, url, *args, **kwargs)
  File "/usr/share/python-wheels/requests-2.2.1-py2.py3-none-any.whl/requests/sessions.py", line 455, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/share/python-wheels/requests-2.2.1-py2.py3-none-any.whl/requests/sessions.py", line 558, in send
    r = adapter.send(request, **kwargs)
  File "/usr/share/python-wheels/requests-2.2.1-py2.py3-none-any.whl/requests/adapters.py", line 385, in send
    raise SSLError(e)
SSLError: [Errno 1] _ssl.c:510: error:14077438:SSL    routines:SSL23_GET_SERVER_HELLO:tlsv1 alert internal error

Storing debug log for failure in /home/ramy/.pip/pip.log
ramy@ramy-Aspire-4739Z:~$

Body:
Requests can verify SSL certificates for HTTPS requests, just like a
  web browser. To check a host’s SSL certificate, you can use the verify
  argument:

And if you want to avoid the SSLError you can find the requests part and change verify to False:

requests.get('https://google.com', verify=False)

Another way reinstall certifi module:

sudo pip uninstall -y certifi
sudo pip install certifi==2015.04.28

Have a look at these questions:

Python Requests throwing up SSLError

SSLError: bad handshake, Python requests


问:
How to start and stop application pool in IIS using powershell script
I want to start and stop application pool in IIS using powershell script. I had try to write the script but i didn't get this.</p>

答:
These days the IISAdminstration module has mostly superceded WebAdministration.

So if you're on Windows 10 / Server 2016, you can use Get-IISAppPool like this:

```<code>Import-Module IISAdministration
(Get-IISAppPool "name").Recycle()
</code>```

Body:
These days the IISAdminstration module has mostly superceded WebAdministration.

So if you're on Windows 10 / Server 2016, you can use Get-IISAppPool like this:

Import-Module IISAdministration
(Get-IISAppPool "name").Recycle()

ContentLicense: CC BY-SA 4.0


问:
How to select text between the specific occurrences of particular characters
How can I select text between the specific occurrences of particular characters?

For example in below string:

Lorem|Ipsum|is|simply|dummy|text|A123|the|printing|and|typesetting|industry|

I want to remove/replace text between the 6th and 7th occurrence of '|' character, i.e. the word 'A123'.

Is it possible to do so with Regex?

答:
You can use counter quantifiers, usually denoted by numbers within curly braces (e.g., pattern{7}). For example this sed command replaces A123 with REP:

```<code>sed 's/\(\([^|]*|\)\{6\}\)[^|]*/\1REP/'
</code>```

Body:
You can use counter quantifiers, usually denoted by numbers within curly braces (e.g., pattern{7}). For example this sed command replaces A123 with REP:

sed 's/\(\([^|]*|\)\{6\}\)[^|]*/\1REP/'


问:
LibWebP is taking too much time for image compression
I'm working on the image compression techniques and analyzing the best algorithms that could produce smaller output within 100 ms or lesser for images of resolution 1920 * 1080 on a laptop with octa core processor for transmission through the network.

I had been using GDI+ and CxImage libraries for image compression, through JPG or PNG compression techniques that gives me the output image within around 30 ms for JPG and around 70 ms using PNG for colorful images, time taken is pretty good but the compressed data size is much higher in size if I go for better quality.

Then I came across google's WebP format. I tried it using libWebP with VC++. The quality and the compression rate is really awesome but the time taken is is much higher than I expected. It takes more than 300 ms and sime times even more than 1 second if I set true for alpha filtering and alpha compression.

Here are my WebpConfig settings

```<code>    m_webp_config.quality           = 50;
    m_webp_config.alpha_quality     = 0;
    m_webp_config.lossless          = false;
    m_webp_config.method            = 3;
    m_webp_config.alpha_compression = false;
    m_webp_config.alpha_filtering   = false;
    m_webp_config.autofilter        = false;
    m_webp_config.filter_sharpness  = false;
    m_webp_config.filter_strength   = 0;
    m_webp_config.filter_type       = 0;
    m_webp_config.use_sharp_yuv     = false;
</code>```

And sometimes I get black images whenever I capture command prompt or notepad++ (I suspect that the problem is with those images with lot of text data but the same is not true with web pages that has huge amount of text)

Am I doing anything wrong with the WebPConfig ? Is there a way to optimize it?.

I didn't find much documentation and any forums that can give me some idea with these problems.

Any help would be appreciated. Thanks in advance.

答:
Try lossless compression? There can be modes of lossless that are faster than the lossy.

If you are in control of the compression and decompression, split the image into 256x256 squares and compress and send them separately. That way you can not only parallelize the computation, but also interleave some of the transmission to happen during the compression, which may simplify your time budgeting for the compression computation.

If you reduce the 'method' value, you will generally find a faster WebP compression. For lossless, you need to reduce BOTH method and quality, they control the same thing in a complicated manner. For lossless, try quality 20 and method 1 (or perhaps there is a 0 method, too, don't remember).

Body:
I'm working on the image compression techniques and analyzing the best algorithms that could produce smaller output within 100 ms or lesser for images of resolution 1920 * 1080 on a laptop with octa core processor for transmission through the network.

I had been using GDI+ and CxImage libraries for image compression, through JPG or PNG compression techniques that gives me the output image within around 30 ms for JPG and around 70 ms using PNG for colorful images, time taken is pretty good but the compressed data size is much higher in size if I go for better quality.

Then I came across google's WebP format. I tried it using libWebP with VC++. The quality and the compression rate is really awesome but the time taken is is much higher than I expected. It takes more than 300 ms and sime times even more than 1 second if I set true for alpha filtering and alpha compression.

Here are my WebpConfig settings

    m_webp_config.quality           = 50;
    m_webp_config.alpha_quality     = 0;
    m_webp_config.lossless          = false;
    m_webp_config.method            = 3;
    m_webp_config.alpha_compression = false;
    m_webp_config.alpha_filtering   = false;
    m_webp_config.autofilter        = false;
    m_webp_config.filter_sharpness  = false;
    m_webp_config.filter_strength   = 0;
    m_webp_config.filter_type       = 0;
    m_webp_config.use_sharp_yuv     = false;

And sometimes I get black images whenever I capture command prompt or notepad++ (I suspect that the problem is with those images with lot of text data but the same is not true with web pages that has huge amount of text)

Am I doing anything wrong with the WebPConfig ? Is there a way to optimize it?.

I didn't find much documentation and any forums that can give me some idea with these problems.

Any help would be appreciated. Thanks in advance.


问:
blank PNG UIImageView
Hopefully a quick one for someone?! I am TOTALLY at a loss.
I have two images,

p1-slide01.png and p3-slide01.png

Both PNG images open in Preview and when I click on them in Xcode, I see them. They are there. They are in the right folder etc.

Yet, when I do myImage.image = [UIImage imageNamed:@"p1-slide01.png"] it doesn't work. It does however work for p3-slide01.png. The code is no different. I have generated the PNG images via an export in PowerPoint. They look fine everywhere.

Does anyone know what I might be doing wrong?! The UIImageViews are declared and retained in the .h file.

[UPDATE] - I renamed the image to "testy.png" and it loaded. Yet when I changed it back to the original p1-slide01.png - it comes up blank. It's like there are cached images somewhere (I've used these file names in another app?!) - do I just need to change file names?!

答: Make sure you clean your build, there may be an additional p1-slide01.png loitering around.

Title: blank PNG UIImageView


问:
Difference between Strings added directly and with references
I came across a question asking the output of the below:

```<code>    String s1 = "String 1";
    String s2 = "String 2";

    String s3 = s1 + s2;
    String s4 = "String 1" + "String 2";

    System.out.println(s3==s4);
</code>```

Output - false

Now, since the strings are not created using new operator, so the objects are created in the string pool, so as per my understanding s1 + s2 and "String 1" + "String 2" should be equal, and s3==s4 should be true.

But it is not happening in real. Can any one please explain this?

答:
The concatenation is happening at runtime, unless both operands are compile-time constant expressions.

Put a final modifier before s1 and s2, and the result will be true, because the compiler will simply replace

```<code>String s3 = s1 + s2;
</code>```

by

```<code>String s3 = "String 1String 2";
</code>```

If you don't, a new String is created at runtime, by appending both strings to a StringBuilder and getting the result.

Note that, although that is interesting from an intellectual point of view, in practice, you shouldn't care about that performance optimization, and always compare Strings with equals().

Body:
I came across a question asking the output of the below:

    String s1 = "String 1";
    String s2 = "String 2";

    String s3 = s1 + s2;
    String s4 = "String 1" + "String 2";

    System.out.println(s3==s4);

Output - false

Now, since the strings are not created using new operator, so the objects are created in the string pool, so as per my understanding s1 + s2 and "String 1" + "String 2" should be equal, and s3==s4 should be true.

But it is not happening in real. Can any one please explain this?

Body:
The concatenation is happening at runtime, unless both operands are compile-time constant expressions.

Put a final modifier before s1 and s2, and the result will be true, because the compiler will simply replace

String s3 = s1 + s2;

by

String s3 = "String 1String 2";

If you don't, a new String is created at runtime, by appending both strings to a StringBuilder and getting the result.

Note that, although that is interesting from an intellectual point of view, in practice, you shouldn't care about that performance optimization, and always compare Strings with equals().


问:
How to ignore specfic xml elements using xmlunit when comparing two xml files in junit
I tried to write a test case in JUnit for comparing two xml files. Using xmlunit, I should be able to find all the differences. But while comparing, I'm getting false all the time, though I am giving similar kind of files. Timestamp is different for each xml file. So, though all the other contents in xml file are equal, it is returning false. Please provide me any proper way to handle this problem.

I need to ignore the timestamp tag in the xml file when comparing two xml files. And how do I ignore self closing tags?

```<code><XML>
<TIMESTAMP>KALA</TIMESTAMP>
<B>JIHN</B>
<C>Lion</C>
</XML>

<XML>
<TIMESTAMP>QWER</TIMESTAMP>
<B>JIHN</B>
<C NAME =LION/>
</XML>
<B>JIHN</B>
</code>```

答:
XMLUnit 2.x has the concept of NodeFilters, using that you can easily ignore the TIMESTAMP elements. Something like

```<code>String control = "<XML>\n"
    + "<TIMESTAMP>KALA</TIMESTAMP>\n"
    + "<B>JIHN</B>\n"
    + "<C>Lion</C>\n"
    + "</XML>";
String test = "<XML>\n"
    + "<TIMESTAMP>QWER</TIMESTAMP>\n"
    + "<B>JIHN</B>\n"
    + "<C NAME=\"LION\"/>\n"
    + "</XML>";
Diff d = DiffBuilder.compare(Input.fromString(control))
    .withTest(Input.fromString(test))
    .withNodeFilter(n -> !(n instanceof Element && Nodes.getQName(n).getLocalPart().equals("TIMESTAMP")))
    .build();
</code>```

could be a start.

I'm not sure what you mean by self-closing tags. <x></x> and <x/> are identical as far as XMLUnit is concerned. The C elements in your example clearly are not. The first one has no attributes but a nested text, the second one has an attribute named NAME but no nested test.

Body:
I tried to write a test case in JUnit for comparing two xml files. Using xmlunit, I should be able to find all the differences. But while comparing, I'm getting false all the time, though I am giving similar kind of files. Timestamp is different for each xml file. So, though all the other contents in xml file are equal, it is returning false. Please provide me any proper way to handle this problem.

I need to ignore the timestamp tag in the xml file when comparing two xml files. And how do I ignore self closing tags?

<XML>
<TIMESTAMP>KALA</TIMESTAMP>
JIHN
<C>Lion</C>
</XML>

<XML>
<TIMESTAMP>QWER</TIMESTAMP>
JIHN
<C NAME =LION/>
</XML>
JIHN

Body:
XMLUnit 2.x has the concept of NodeFilters, using that you can easily ignore the TIMESTAMP elements. Something like

String control = "<XML>\n"
    + "<TIMESTAMP>KALA</TIMESTAMP>\n"
    + "<B>JIHN</B>\n"
    + "<C>Lion</C>\n"
    + "</XML>";
String test = "<XML>\n"
    + "<TIMESTAMP>QWER</TIMESTAMP>\n"
    + "<B>JIHN</B>\n"
    + "<C NAME=\"LION\"/>\n"
    + "</XML>";
Diff d = DiffBuilder.compare(Input.fromString(control))
    .withTest(Input.fromString(test))
    .withNodeFilter(n -> !(n instanceof Element && Nodes.getQName(n).getLocalPart().equals("TIMESTAMP")))
    .build();

could be a start.

I'm not sure what you mean by self-closing tags. <x></x> and <x/> are identical as far as XMLUnit is concerned. The C elements in your example clearly are not. The first one has no attributes but a nested text, the second one has an attribute named NAME but no nested test.


问:
Finding the largest palindrome of the product of two 3-digit numbers in Python
So the challenge I'm trying to solve is to find the largest palindrome made from the product of two 3-digit numbers. I'm new to Python and so my code is not elegant or refracted yet, but there is a logical error that I can't seem to find.

```<code>def ispalindrome(n):
    rev_n = str(n)[::-1]
    if n == rev_n:
        return True
    else:
        return False

first_num = 100
second_num = 100
mylist=[]
while first_num < 1000:
    while second_num < 1000:
        item = first_num * second_num
        mylist.append(item)
        second_num += 1
    second_num = 100
    first_num +=1
# print (mylist)
num_as_string = []
for i in mylist:
    i = str(i)
    num_as_string.append(i)
print("Total products of two 3-digit numbers: {}").format(len(num_as_string))
print("-----------------------------------------------------")

def convert_to_num_list(string_list):
    new_num_list = []
    item = int(string_list)
    new_num_list.append(item)
    return new_num_list

palindrome_list = []

for j in num_as_string:
    if ispalindrome(j) == True:
        palindrome_list.append(j)
        palindrome_list.sort()
        # print(palindrome_list)
        x = convert_to_num_list(j)
        largest_palindrome = max(x)

print("Total palindroms of product of two 3-digit numers: {}").format(len(palindrome_list))

print("Largest palindrome = {}").format(largest_palindrome)
</code>```

The problem is that I'm getting the largest palindrome as 580085, which is 995*583 but is NOT the largest palindrome. I believe the largest palindrome is 906609, which is 993*913, but my code is not finding this. Can anyone help me with the flaw in my logic?

答:
Here is a function for finding the largest palindrome of the product of two 3-digit numbers that I found in stackoverflow.

Link to what i found- https://stackoverflow.com/a/7460573

```<code>def is_pal(c):
       return int(str(c)[::-1]) == c

   maxpal = 0
   for a in range(999, 99, -1):
       for b in range(a, 99, -1):
           prod = a * b
           if is_pal(prod) and prod > maxpal:
               maxpal = prod

   print maxpal
</code>```

Body:
So the challenge I'm trying to solve is to find the largest palindrome made from the product of two 3-digit numbers. I'm new to Python and so my code is not elegant or refracted yet, but there is a logical error that I can't seem to find.

def ispalindrome(n):
    rev_n = str(n)[::-1]
    if n == rev_n:
        return True
    else:
        return False

first_num = 100
second_num = 100
mylist=[]
while first_num < 1000:
    while second_num < 1000:
        item = first_num * second_num
        mylist.append(item)
        second_num += 1
    second_num = 100
    first_num +=1
# print (mylist)
num_as_string = []
for i in mylist:
    i = str(i)
    num_as_string.append(i)
print("Total products of two 3-digit numbers: {}").format(len(num_as_string))
print("-----------------------------------------------------")

def convert_to_num_list(string_list):
    new_num_list = []
    item = int(string_list)
    new_num_list.append(item)
    return new_num_list

palindrome_list = []

for j in num_as_string:
    if ispalindrome(j) == True:
        palindrome_list.append(j)
        palindrome_list.sort()
        # print(palindrome_list)
        x = convert_to_num_list(j)
        largest_palindrome = max(x)

print("Total palindroms of product of two 3-digit numers: {}").format(len(palindrome_list))

print("Largest palindrome = {}").format(largest_palindrome)

The problem is that I'm getting the largest palindrome as 580085, which is 995*583 but is NOT the largest palindrome. I believe the largest palindrome is 906609, which is 993*913, but my code is not finding this. Can anyone help me with the flaw in my logic?

Body:
Here is a function for finding the largest palindrome of the product of two 3-digit numbers that I found in stackoverflow.

Link to what i found- https://stackoverflow.com/a/7460573

def is_pal(c):
       return int(str(c)[::-1]) == c

   maxpal = 0
   for a in range(999, 99, -1):
       for b in range(a, 99, -1):
           prod = a * b
           if is_pal(prod) and prod > maxpal:
               maxpal = prod

   print maxpal


问:
How to transfer data between view controller using segues
I'm trying to pass data using a prepare(for segue:) function but it's showing nil in the second VC. Am I doing anything wrong?

```<code>class ViewController: UIViewController {

    var first : [String] = []

    @IBOutlet weak var passField: UITextField!
    @IBOutlet weak var userID: UITextField!

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    @IBAction func login(_ sender: Any) {
        let user : String = self.userID.text!
        let password : String = self.passField.text!

        if user != "" && password != "" {
            let postString = ["username":user, “password”: password]
            var request = URLRequest(url:URL(string:"http://mydomainhere.com/api/login")!)
            request.httpMethod = "POST"
            request.httpBody = try! JSONSerialization.data(withJSONObject: postString, options:.prettyPrinted)
            let task = URLSession.shared.dataTask(with: request) { (data: Data?, response: URLResponse?, error: Error?) in
                if error != nil {
                    print("error=\(error)")
                    return
                }

                do {
                    if let json = try JSONSerialization.jsonObject(with: data!, options: .allowFragments) as? [String: Any] {
                        let firstName = json["first_name"] as? String
                        let lastName = json["last_name"] as? String
                        self.first.append(firstName!) //putting into Array
                        self.performSegue(withIdentifier: "loginSegue", sender: self)
                    }
                } catch {
                    print(error)
                }
            }
        }
    }

    // data transfer to another controller
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if segue.identifier == "loginSegue" {
            let secondController = segue.destination as? SecondVC
            secondController?.name = first //passing to next VC   //* here having the issue its not passing the data to next VC
            print(first)    // here first is printing perfectly
        }
    }
}

// second View Controller
class SecondVC: UIViewController {

    var menu_vc : MenuViewController!
    var name : [String]?    // passing to this Array

    override func viewDidLoad() {
        super.viewDidLoad()
        print(name)    // here printing nil
    }
}
</code>```

答:
As suggested by @Sweeper, it could very well be that your destination view controller is embedded in a UINavigationViewController, hence your segue.destination is in fact a UINavigationViewController, not a SecondVC.

You can try this code:

```<code>override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    var destinationViewController = segue.destination
    if let navigationController = destinationViewController as? UINavigationController {
        destinationViewController = navigationController.visibleViewController ?? destinationViewController
    }
    if let secondController = destinationViewController as? SecondVC {
        secondController?.name = first
    }
}
</code>```

Of course the first four lines of code could be refactored in an appropriate function (even better if in an extension of UIViewController).

If that solves the problem, you can watch cs193p Stanford iOS course for further details.
In particular watch https://www.youtube.com/watch?v=HQrXM2zUPvY&index=6&list=PLPA-ayBrweUz32NSgNZdl0_QISw-f12Ai starting from the 30:20 mark.

Body:
I'm trying to pass data using a prepare(for segue:) function but it's showing nil in the second VC. Am I doing anything wrong?

class ViewController: UIViewController {

    var first : [String] = []

    @IBOutlet weak var passField: UITextField!
    @IBOutlet weak var userID: UITextField!

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    @IBAction func login(_ sender: Any) {
        let user : String = self.userID.text!
        let password : String = self.passField.text!

        if user != "" && password != "" {
            let postString = ["username":user, “password”: password]
            var request = URLRequest(url:URL(string:"http://mydomainhere.com/api/login")!)
            request.httpMethod = "POST"
            request.httpBody = try! JSONSerialization.data(withJSONObject: postString, options:.prettyPrinted)
            let task = URLSession.shared.dataTask(with: request) { (data: Data?, response: URLResponse?, error: Error?) in
                if error != nil {
                    print("error=\(error)")
                    return
                }

                do {
                    if let json = try JSONSerialization.jsonObject(with: data!, options: .allowFragments) as? [String: Any] {
                        let firstName = json["first_name"] as? String
                        let lastName = json["last_name"] as? String
                        self.first.append(firstName!) //putting into Array
                        self.performSegue(withIdentifier: "loginSegue", sender: self)
                    }
                } catch {
                    print(error)
                }
            }
        }
    }

    // data transfer to another controller
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if segue.identifier == "loginSegue" {
            let secondController = segue.destination as? SecondVC
            secondController?.name = first //passing to next VC   //* here having the issue its not passing the data to next VC
            print(first)    // here first is printing perfectly
        }
    }
}

// second View Controller
class SecondVC: UIViewController {

    var menu_vc : MenuViewController!
    var name : [String]?    // passing to this Array

    override func viewDidLoad() {
        super.viewDidLoad()
        print(name)    // here printing nil
    }
}

Body:
As suggested by @Sweeper, it could very well be that your destination view controller is embedded in a UINavigationViewController, hence your segue.destination is in fact a UINavigationViewController, not a SecondVC.

You can try this code:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    var destinationViewController = segue.destination
    if let navigationController = destinationViewController as? UINavigationController {
        destinationViewController = navigationController.visibleViewController ?? destinationViewController
    }
    if let secondController = destinationViewController as? SecondVC {
        secondController?.name = first
    }
}

Of course the first four lines of code could be refactored in an appropriate function (even better if in an extension of UIViewController).

If that solves the problem, you can watch cs193p Stanford iOS course for further details.
In particular watch https://www.youtube.com/watch?v=HQrXM2zUPvY&index=6&list=PLPA-ayBrweUz32NSgNZdl0_QISw-f12Ai starting from the 30:20 mark.


问:
Matrix Multiplication A^T * A in PySpark
I asked a similar question yesterday - Matrix Multiplication between two RDD[Array[Double]] in Spark - however I've decided to shift to pyspark to do this. I've made some progress loading and reformatting the data - Pyspark map from RDD of strings to RDD of list of doubles - however the matrix multiplcation is difficult. Let me share my progress first:

```<code>matrix1.txt
1.2 3.4 2.3
2.3 1.1 1.5
3.3 1.8 4.5
5.3 2.2 4.5
9.3 8.1 0.3
4.5 4.3 2.1
</code>```

it's difficult to share files, however this is what my matrix1.txt file looks like. It is a space-delimited text file including the values of a matrix. Next is the code:

```<code># do the imports for pyspark and numpy
from pyspark import SparkConf, SparkContext
import numpy as np

# loadmatrix is a helper function used to read matrix1.txt and format
# from RDD of strings to RDD of list of floats
def loadmatrix(sc):
    data = sc.textFile("matrix1.txt").map(lambda line: line.split(' ')).map(lambda line: [float(x) for x in line])
    return(data)

# this is the function I am struggling with, it should take a line of the
# matrix (formatted as list of floats), compute an outer product with itself
def AtransposeA(line):
    # pseudocode for this would be...
    # outerprod = compute line * line^transpose
    # return(outerprod)

# here is the main body of my file
if __name__ == "__main__":
    # create the conf, sc objects, then use loadmatrix to read data
    conf = SparkConf().setAppName('SVD').setMaster('local')
    sc = SparkContext(conf = conf)
    mymatrix = loadmatrix(sc)

    # this is pseudocode for calling AtransposeA
    ATA = mymatrix.map(lambda line: AtransposeA(line)).reduce(elementwise add all the outerproducts)

    # the SVD of ATA is computed below
    U, S, V = np.linalg.svd(ATA)

    # ...
</code>```

My approach is as follows - to do matrix multiplication A^T * A, I create a function that computes outer products of rows of A. The elementwise sum of all of the outerproducts is the product I want. I then call AtransposeA() in a map function, that way is it performed on each row of the matrix, and finally I use a reduce() to add the resulting matrices.

I'm struggling thinking about how the AtransposeA function should look. How can I do an outerproduct in pyspark like this? Thanks in advance for help!

答:
First, consider why you want to use Spark for this. It sounds like all your data fits in memory, in which case you can use numpy and pandas in a very straight-forward way.

If your data isn't structured so that rows are independent, then it probably can't be parallelized by sending groups of rows to different nodes, which is the whole point of using Spark.

Having said that... here is some pyspark (2.1.1) code that I think does what you want.

```<code># read the matrix file
df = spark.read.csv("matrix1.txt",sep=" ",inferSchema=True)
df.show()
+---+---+---+
|_c0|_c1|_c2|
+---+---+---+
|1.2|3.4|2.3|
|2.3|1.1|1.5|
|3.3|1.8|4.5|
|5.3|2.2|4.5|
|9.3|8.1|0.3|
|4.5|4.3|2.1|
+---+---+---+
# do the sum of the multiplication that we want, and get
# one data frame for each column
colDFs = []
for c2 in df.columns:
    colDFs.append( df.select( [ F.sum(df[c1]*df[c2]).alias("op_{0}".format(i)) for i,c1 in enumerate(df.columns) ] ) )
# now union those separate data frames to build the "matrix"
mtxDF = reduce(lambda a,b: a.select(a.columns).union(b.select(a.columns)), colDFs )
mtxDF.show()
+------------------+------------------+------------------+
|              op_0|              op_1|              op_2|
+------------------+------------------+------------------+
|            152.45|118.88999999999999|             57.15|
|118.88999999999999|104.94999999999999|             38.93|
|             57.15|             38.93|52.540000000000006|
+------------------+------------------+------------------+
</code>```

This seems to be the same result that you get from numpy.

```<code>a = numpy.genfromtxt("matrix1.txt")
numpy.dot(a.T, a)
array([[ 152.45,  118.89,   57.15],
       [ 118.89,  104.95,   38.93],
       [  57.15,   38.93,   52.54]])
</code>```

Body:
I asked a similar question yesterday - Matrix Multiplication between two RDD[Array[Double]] in Spark - however I've decided to shift to pyspark to do this. I've made some progress loading and reformatting the data - Pyspark map from RDD of strings to RDD of list of doubles - however the matrix multiplcation is difficult. Let me share my progress first:

matrix1.txt
1.2 3.4 2.3
2.3 1.1 1.5
3.3 1.8 4.5
5.3 2.2 4.5
9.3 8.1 0.3
4.5 4.3 2.1

it's difficult to share files, however this is what my matrix1.txt file looks like. It is a space-delimited text file including the values of a matrix. Next is the code:

# do the imports for pyspark and numpy
from pyspark import SparkConf, SparkContext
import numpy as np

# loadmatrix is a helper function used to read matrix1.txt and format
# from RDD of strings to RDD of list of floats
def loadmatrix(sc):
    data = sc.textFile("matrix1.txt").map(lambda line: line.split(' ')).map(lambda line: [float(x) for x in line])
    return(data)

# this is the function I am struggling with, it should take a line of the
# matrix (formatted as list of floats), compute an outer product with itself
def AtransposeA(line):
    # pseudocode for this would be...
    # outerprod = compute line * line^transpose
    # return(outerprod)

# here is the main body of my file
if __name__ == "__main__":
    # create the conf, sc objects, then use loadmatrix to read data
    conf = SparkConf().setAppName('SVD').setMaster('local')
    sc = SparkContext(conf = conf)
    mymatrix = loadmatrix(sc)

    # this is pseudocode for calling AtransposeA
    ATA = mymatrix.map(lambda line: AtransposeA(line)).reduce(elementwise add all the outerproducts)

    # the SVD of ATA is computed below
    U, S, V = np.linalg.svd(ATA)

    # ...

My approach is as follows - to do matrix multiplication A^T * A, I create a function that computes outer products of rows of A. The elementwise sum of all of the outerproducts is the product I want. I then call AtransposeA() in a map function, that way is it performed on each row of the matrix, and finally I use a reduce() to add the resulting matrices.

I'm struggling thinking about how the AtransposeA function should look. How can I do an outerproduct in pyspark like this? Thanks in advance for help!

Body:
First, consider why you want to use Spark for this. It sounds like all your data fits in memory, in which case you can use numpy and pandas in a very straight-forward way.

If your data isn't structured so that rows are independent, then it probably can't be parallelized by sending groups of rows to different nodes, which is the whole point of using Spark.

Having said that... here is some pyspark (2.1.1) code that I think does what you want.

# read the matrix file
df = spark.read.csv("matrix1.txt",sep=" ",inferSchema=True)
df.show()
+---+---+---+
|_c0|_c1|_c2|
+---+---+---+
|1.2|3.4|2.3|
|2.3|1.1|1.5|
|3.3|1.8|4.5|
|5.3|2.2|4.5|
|9.3|8.1|0.3|
|4.5|4.3|2.1|
+---+---+---+
# do the sum of the multiplication that we want, and get
# one data frame for each column
colDFs = []
for c2 in df.columns:
    colDFs.append( df.select( [ F.sum(df[c1]*df[c2]).alias("op_{0}".format(i)) for i,c1 in enumerate(df.columns) ] ) )
# now union those separate data frames to build the "matrix"
mtxDF = reduce(lambda a,b: a.select(a.columns).union(b.select(a.columns)), colDFs )
mtxDF.show()
+------------------+------------------+------------------+
|              op_0|              op_1|              op_2|
+------------------+------------------+------------------+
|            152.45|118.88999999999999|             57.15|
|118.88999999999999|104.94999999999999|             38.93|
|             57.15|             38.93|52.540000000000006|
+------------------+------------------+------------------+

This seems to be the same result that you get from numpy.

a = numpy.genfromtxt("matrix1.txt")
numpy.dot(a.T, a)
array([[ 152.45,  118.89,   57.15],
       [ 118.89,  104.95,   38.93],
       [  57.15,   38.93,   52.54]])


问:
Java: how to modify instance variable of a child class
The story goes like this:

I have an abstract class called Algorithms and a lot of classes that extend it. Some of them have parameters to tune. Some have none, and some have up to 5.

I would like to have a method in Algorithms that can tune an arbitrary parameter. e.g.:

```<code>public static void tune (String paramName, double minValue, double MaxValue)
{ ... }
</code>```

So that I can call it like this on 'class SoftRankBoots extends Algorithm':

```<code>Algorithm srb = new SoftRankBoost();
srb.tune("delta", 0, 1);
</code>```

Note that SoftRankBoost has an instance variable 'double delta';

How can I achieve this?

Thank you.

答: I think the sub-classes of 'Algorithm' class are differ from each other, so the Template Method pattern or the Strategy pattern may give you some useful concept to solve your problem.</p>

Body:
The story goes like this:

I have an abstract class called Algorithms and a lot of classes that extend it. Some of them have parameters to tune. Some have none, and some have up to 5.

I would like to have a method in Algorithms that can tune an arbitrary parameter. e.g.:

public static void tune (String paramName, double minValue, double MaxValue)
{ ... }

So that I can call it like this on 'class SoftRankBoots extends Algorithm':

Algorithm srb = new SoftRankBoost();
srb.tune("delta", 0, 1);

Note that SoftRankBoost has an instance variable 'double delta';

How can I achieve this?

Thank you.


问:
How is data counted in an ajax-call?
I will use AJAX for a pagination script and wanna make this script as "data consumption saving" as possible. Therefore my idea is to just load the items for the chosen page and just load empty li-items with data-id for all items not showing.

The question is if this really is data consumption saving if the php file called by ajax is going through all the data anyway.

I guess the question is; does the data count in how much content there is in the ajax-response, or is it counted by how big the ajax-call to the php file is?

Do I save any data by leaving a lot of li-items empty or could I just as good add the content since it loaded in the ajax-call anyway?

Does anyone understand how I mean?

People always want code example:

```<code>jQuery.post(ajaxurl, 'action=load_items', function(response)
{
            // Is it the action 'action=load_items'
            // that consumes data? Or is it the amount
            // of data coming out in the response?
});
</code>```

答:
I guess you want to minimize the data a client (who's visiting the website) consumes (e.g. because of a small data plan on a mobile phone). Is this correct?

If so, you need to think about what is actually sent from your website to the client. The PHP script echos some data, and only this data is transferred to the client. So, what you actually read in during the calculation (and hold in the server's memory) is not relevant. It is relevant what you actually put out and send to the client.

This said, you can optimize the output of your script. First, you should enable GZIP. This saves the most data and every browser understands it. In PHP, this is very easy (see detailed answer). Just add ob_start("ob_gzhandler"); before your output.

Second, you should minify the JSON you send back to the client. You can do this by just using the default function json_encode(). This will remove you all unnecessary white space in the JSON.

If you now send only data chunks instead of the whole data set, it would probably be the most data-savy way to do that. Keep in mind, that there is always a HTTP header which needs to be transmitted too. So don't make too small data packages if you want to optimize the data consumption (ideally, you send exactly what the average user wants to see in one package).

You can track the data consumption of your website in the Network tab of e.g. Google Chrome's Dev Tools (I'm sure this is also available in other browsers). Every Ajax call is listed there together with its size (you can filter it with XHR).

Title: How is data counted in an ajax-call?

Body:
I will use AJAX for a pagination script and wanna make this script as "data consumption saving" as possible. Therefore my idea is to just load the items for the chosen page and just load empty li-items with data-id for all items not showing.

The question is if this really is data consumption saving if the php file called by ajax is going through all the data anyway.

I guess the question is; does the data count in how much content there is in the ajax-response, or is it counted by how big the ajax-call to the php file is?

Do I save any data by leaving a lot of li-items empty or could I just as good add the content since it loaded in the ajax-call anyway?

Does anyone understand how I mean?

People always want code example:

jQuery.post(ajaxurl, 'action=load_items', function(response)
{
            // Is it the action 'action=load_items'
            // that consumes data? Or is it the amount
            // of data coming out in the response?
});


问:
svg circle path animation
I would like to create an animation with SVG and have here a few problems.
The small circle shall move along the path of the great circle.
Can someone here show me the way with a few hints or a simple example?
I tried it with css but this is not the right way to go.</p>

```<code><!doctype html>
<html lang="en">
<head>
</head>
<body>
  <svg>
    <circle id="c1" cx="100" cy="100" r="90" stroke="#ccc" stroke-width="2" fill="none"/>
    <circle id ="c2" cx="100" cy="10" r="8" stroke="#f00" stroke-width="3" fill="#fff"/>
  </svg>
  <script>
    circle1=document.getElementById("c1");
    circle2=document.getElementById("c2");

    for (i=1;i<60;i++){
      // here is must calc the points
      //of the path of the circle
      //that is difficult but not such a problem
      //but i don´t see an animation
      //but I see no animation
      circle2.setAttribute("cx",100+i);
      circle2.setAttribute("cy",100+i);
    }
  </script>
</body>
</html>
</code>```

答:
a good day and welcome,

I think the way to calculate the points of the circle is too elaborate. It is easier to rotate your circle with transform rotate.

Last week I answered a similar question in a seminar as follows:

(Please read it intensive and also the remarks. I hope you understand the code.)

<!doctype html>

  <meta charset="UTF-8">
  <title>Document</title>

  <svg id = "mySVG" width="200" height="200" viewBox="0 0 200 200">
    <circle id = "myCirclePath" cx="100" cy="100" r="90" stroke="#ccc" stroke-width="2" fill="none"/>
    <circle id = "myAniCircle" cx="100" cy="10" r="8" stroke="#f00" stroke-width="3" fill="#fff"/>
  </svg>

```

Title: svg circle path animation

Body:
I would like to create an animation with SVG and have here a few problems.
The small circle shall move along the path of the great circle.
Can someone here show me the way with a few hints or a simple example?
I tried it with css but this is not the right way to go.

<!doctype html>

  <svg>
    <circle id="c1" cx="100" cy="100" r="90" stroke="#ccc" stroke-width="2" fill="none"/>
    <circle id ="c2" cx="100" cy="10" r="8" stroke="#f00" stroke-width="3" fill="#fff"/>
  </svg>

Body:
a good day and welcome,

I think the way to calculate the points of the circle is too elaborate. It is easier to rotate your circle with transform rotate.

Last week I answered a similar question in a seminar as follows:

(Please read it intensive and also the remarks. I hope you understand the code.)

<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
</head>
<body>
  <svg id = "mySVG" width="200" height="200" viewBox="0 0 200 200">
    <circle id = "myCirclePath" cx="100" cy="100" r="90" stroke="#ccc" stroke-width="2" fill="none"/>
    <circle id = "myAniCircle" cx="100" cy="10" r="8" stroke="#f00" stroke-width="3" fill="#fff"/>
  </svg>
  <script>
    var animateAtCircle = function (elementToAnimate, circlePath, duration, callback){
      //I would see:
      var imagesPerSecond = 60;
      //and calculate the sum of steps i need:
      var sumSteps = duration / (1000/imagesPerSecond);
      //an circle has 360 degrees
      //so my stepwidth is:
      var stepWidth = 360 / sumSteps
      //let us begin with step 1
      var step = 1;
      //before, i need a Variable to store my Timeout
      var pathAnim;
      //and begin with our animation function
      var anim=function(){
        //rotate the circle relative
        //to the midpoint of circlePath
        elementToAnimate.setAttribute("transform",`rotate(
          ${step*stepWidth},
          ${circlePath.getAttribute('cx')},
          ${circlePath.getAttribute('cy')}
          )`);
        //until step smaller then sumSteps
        if ( step < sumSteps){
          //set step to next step
          step ++
          //and wait for creating next rotation an call anim again...
          pathAnim = setTimeout(anim, 1000/imagesPerSecond);
        } else {
          //animation is finished;
          clearTimeout(pathAnim);
          //call callback function
          if (callback) return callback();
        }
      }
      //now call our anim loop function
      anim();
    }
    //now call our Aimation at circle...
    animateAtCircle(myAniCircle,myCirclePath,5000, function(){console.log('finished');});
  </script>
</body>
</html>


问:
What does corner.ravel() does?
I couldn't understand the use of corner.ravel() in a source code regarding corner detection.

Here is the corresponding source code:

```<code>import numpy as np
import cv2
from matplotlib import pyplot as plt

img = cv2.imread('simple.jpg')
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

corners = cv2.goodFeaturesToTrack(gray,25,0.01,10)
corners = np.int0(corners)

for corner in corners:
    x,y = corner.ravel()
    cv2.circle(img,(x,y),3,255,-1)

plt.imshow(img),plt.show()
</code>```

If someone can explain, it will be great help.
Thank You!

答: .ravel(), is an attribute to numpy matrices, which can be used to faltten the src Matrix, there are other similar APIs' as well which can be used for this purpose such as : .flatten(), .reshape()

Title: What does corner.ravel() does?

Body:
I couldn't understand the use of corner.ravel() in a source code regarding corner detection.

Here is the corresponding source code:

import numpy as np
import cv2
from matplotlib import pyplot as plt

img = cv2.imread('simple.jpg')
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

corners = cv2.goodFeaturesToTrack(gray,25,0.01,10)
corners = np.int0(corners)

for corner in corners:
    x,y = corner.ravel()
    cv2.circle(img,(x,y),3,255,-1)

plt.imshow(img),plt.show()

If someone can explain, it will be great help.
Thank You!