转自:http://blog.csdn.net/fengbingchun/article/details/37766607

版权声明:本文为博主原创文章,未经博主允许不得转载。

1、  打开Eclipse,File-->New-->AndroidApplication Project-->Application Name:Hello-Neon, Project Name: Hello-Neon,Package Name:com.hello_neon.Android, Minimum Required SDK:API 9:Android 2.3(Gingerbread),Next-->去掉Create custom launcher icon的勾选,Next-->Next-->ActivityName:Hello_NeonProjectActivity,Finish.

2、  打开Hello-Neon工程下的src-->com.hello_neon.android-->Hello_NeonProjectActivity.Java,将其内容改为:

  1. package com.hello_neon.android;
  2. import android.os.Bundle;
  3. import android.app.Activity;
  4. import android.widget.TextView;
  5. public class Hello_NeonProjectActivity extends Activity {
  6. /** Called when the activity is first created. */
  7. @Override
  8. public void onCreate(Bundle savedInstanceState)
  9. {
  10. super.onCreate(savedInstanceState);
  11. /* Create a TextView and set its content.
  12. * the text is retrieved by calling a native function.
  13. */
  14. TextView  tv = new TextView(this);
  15. tv.setText( stringFromJNI() );
  16. setContentView(tv);
  17. }
  18. /* A native method that is implemented by the
  19. * 'helloneon' native library, which is packaged with this application.
  20. */
  21. public native String  stringFromJNI();
  22. /* this is used to load the 'helloneon' library on application
  23. * startup. The library has already been unpacked into
  24. * /data/data/com.example.neon/lib/libhelloneon.so at
  25. * installation time by the package manager.
  26. */
  27. static {
  28. System.loadLibrary("helloneon");
  29. }
  30. }

3、 保存Hello_NeonProjectActivity.java文件,打开命令行窗口,将其定位到\bin\classes目录下,输入命令:javah –classpath D:\ProgramFiles\Android\android-sdk\platforms\android-9\android.jar;com.hello_neon.android.Hello_NeonProjectActivity ,会在\bin\classes目录下生成com_hello_neon_android_Hello_NeonProjectActivity.h文件(说明:*.jar也可以是其它版本);

4、  选中Hello-Neon工程,点击右键-->New-->Folder新建一个jni文件夹,在此文件夹下添加Android.mk、Application.mk、helloneon.c、helloneon-intrinsics.c、helloneon-intrinsics.h五个文件,其中内容分别为:

Android.mk:

  1. LOCAL_PATH := $(call my-dir)
  2. include $(CLEAR_VARS)
  3. LOCAL_MODULE    := helloneon
  4. #填写要编译的源文件路径
  5. LOCAL_SRC_FILES := helloneon.c helloneon-intrinsics.c
  6. #默认包含的头文件路径
  7. LOCAL_C_INCLUDES := \
  8. $(LOCAL_PATH) \
  9. $(LOCAL_PATH)/..
  10. #-g 后面的一系列项目添加了才能使用arm_neon-h头文件, -mfloat-abi=softfp -mfpu=neon 使用arm_neon.h必须
  11. LOCAL_CFLAGS := -g -mfloat-abi=softfp -mfpu=neon -march=armv7-a -mtune=cortex-a8
  12. LOCAL_LDLIBS := -lz -llog
  13. TARGET_ARCH_ABI := armeabi-v7a
  14. LOCAL_ARM_MODE := arm
  15. ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
  16. #采用NEON优化技术
  17. LOCAL_ARM_NEON := true
  18. #LOCAL_CFLAGS := -DHAVE_NEON=1
  19. endif
  20. LOCAL_STATIC_LIBRARIES := cpufeatures
  21. #生成动态调用库
  22. include $(BUILD_SHARED_LIBRARY)
  23. $(call import-module,cpufeatures)

Application.mk:

  1. APP_PROJECT_PATH := $(call my-dir)/..
  2. APP_PLATFORM := android-10
  3. #choose which library to compile against in your Makefile
  4. APP_STL := stlport_static
  5. #APP_ABI这句指定了编译的目标平台类型,可以针对不同平台进行优化,x86 or armeabi-v7a
  6. # Build both ARMv5TE and ARMv7-A machine code.
  7. APP_ABI := armeabi armeabi-v7a
  8. APP_CPPFLAGS += -fexceptions
  9. #for using c++ features,you need to enable these in your Makefile
  10. APP_CPP_FEATURES += exceptions rtti

helloneon.c:

  1. #include <jni.h>
  2. #include <time.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <cpu-features.h>
  6. #include "helloneon-intrinsics.h"
  7. #define DEBUG 0
  8. #define HAVE_NEON
  9. #if DEBUG
  10. #include <android/log.h>
  11. #  define  D(x...)  __android_log_print(ANDROID_LOG_INFO,"helloneon",x)
  12. #else
  13. #  define  D(...)  do {} while (0)
  14. #endif
  15. /* return current time in milliseconds */
  16. static double
  17. now_ms(void)
  18. {
  19. struct timespec res;
  20. clock_gettime(CLOCK_REALTIME, &res);
  21. return 1000.0*res.tv_sec + (double)res.tv_nsec/1e6;
  22. }
  23. /* this is a FIR filter implemented in C */
  24. static void
  25. fir_filter_c(short *output, const short* input, const short* kernel, int width, int kernelSize)
  26. {
  27. int  offset = -kernelSize/2;
  28. int  nn;
  29. for (nn = 0; nn < width; nn++) {
  30. int sum = 0;
  31. int mm;
  32. for (mm = 0; mm < kernelSize; mm++) {
  33. sum += kernel[mm]*input[nn+offset+mm];
  34. }
  35. output[nn] = (short)((sum + 0x8000) >> 16);
  36. }
  37. }
  38. #define  FIR_KERNEL_SIZE   32
  39. #define  FIR_OUTPUT_SIZE   2560
  40. #define  FIR_INPUT_SIZE    (FIR_OUTPUT_SIZE + FIR_KERNEL_SIZE)
  41. #define  FIR_ITERATIONS    600
  42. static const short  fir_kernel[FIR_KERNEL_SIZE] = {
  43. 0x10, 0x20, 0x40, 0x70, 0x8c, 0xa2, 0xce, 0xf0, 0xe9, 0xce, 0xa2, 0x8c, 070, 0x40, 0x20, 0x10,
  44. 0x10, 0x20, 0x40, 0x70, 0x8c, 0xa2, 0xce, 0xf0, 0xe9, 0xce, 0xa2, 0x8c, 070, 0x40, 0x20, 0x10 };
  45. static short        fir_output[FIR_OUTPUT_SIZE];
  46. static short        fir_input_0[FIR_INPUT_SIZE];
  47. static const short* fir_input = fir_input_0 + (FIR_KERNEL_SIZE/2);
  48. static short        fir_output_expected[FIR_OUTPUT_SIZE];
  49. /* This is a trivial JNI example where we use a native method
  50. * to return a new VM String. See the corresponding Java source
  51. * file located at:
  52. *
  53. *   apps/samples/hello-neon/project/src/com/example/neon/HelloNeon.java
  54. */
  55. JNIEXPORT jstring JNICALL Java_com_hello_1neon_android_Hello_1NeonProjectActivity_stringFromJNI(JNIEnv *env, jobject thiz)
  56. {
  57. char*  str;
  58. uint64_t features;
  59. char buffer[512];
  60. char tryNeon = 0;
  61. double  t0, t1, time_c, time_neon;
  62. /* setup FIR input - whatever */
  63. {
  64. int  nn;
  65. for (nn = 0; nn < FIR_INPUT_SIZE; nn++) {
  66. fir_input_0[nn] = (5*nn) & 255;
  67. }
  68. fir_filter_c(fir_output_expected, fir_input, fir_kernel, FIR_OUTPUT_SIZE, FIR_KERNEL_SIZE);
  69. }
  70. /* Benchmark small FIR filter loop - C version */
  71. t0 = now_ms();
  72. {
  73. int  count = FIR_ITERATIONS;
  74. for (; count > 0; count--) {
  75. fir_filter_c(fir_output, fir_input, fir_kernel, FIR_OUTPUT_SIZE, FIR_KERNEL_SIZE);
  76. }
  77. }
  78. t1 = now_ms();
  79. time_c = t1 - t0;
  80. asprintf(&str, "FIR Filter benchmark:\nC version          : %g ms\n", time_c);
  81. strlcpy(buffer, str, sizeof buffer);
  82. free(str);
  83. strlcat(buffer, "Neon version   : ", sizeof buffer);
  84. if (android_getCpuFamily() != ANDROID_CPU_FAMILY_ARM) {
  85. strlcat(buffer, "Not an ARM CPU !\n", sizeof buffer);
  86. goto EXIT;
  87. }
  88. features = android_getCpuFeatures();
  89. if ((features & ANDROID_CPU_ARM_FEATURE_ARMv7) == 0) {
  90. strlcat(buffer, "Not an ARMv7 CPU !\n", sizeof buffer);
  91. goto EXIT;
  92. }
  93. /* HAVE_NEON is defined in Android.mk ! */
  94. #ifdef HAVE_NEON
  95. if ((features & ANDROID_CPU_ARM_FEATURE_NEON) == 0) {
  96. strlcat(buffer, "CPU doesn't support NEON !\n", sizeof buffer);
  97. goto EXIT;
  98. }
  99. /* Benchmark small FIR filter loop - Neon version */
  100. t0 = now_ms();
  101. {
  102. int  count = FIR_ITERATIONS;
  103. for (; count > 0; count--) {
  104. fir_filter_neon_intrinsics(fir_output, fir_input, fir_kernel, FIR_OUTPUT_SIZE, FIR_KERNEL_SIZE);
  105. }
  106. }
  107. t1 = now_ms();
  108. time_neon = t1 - t0;
  109. asprintf(&str, "%g ms (x%g faster)\n", time_neon, time_c / (time_neon < 1e-6 ? 1. : time_neon));
  110. strlcat(buffer, str, sizeof buffer);
  111. free(str);
  112. /* check the result, just in case */
  113. {
  114. int  nn, fails = 0;
  115. for (nn = 0; nn < FIR_OUTPUT_SIZE; nn++) {
  116. if (fir_output[nn] != fir_output_expected[nn]) {
  117. if (++fails < 16)
  118. D("neon[%d] = %d expected %d", nn, fir_output[nn], fir_output_expected[nn]);
  119. }
  120. }
  121. D("%d fails\n", fails);
  122. }
  123. #else /* !HAVE_NEON */
  124. strlcat(buffer, "Program not compiled with ARMv7 support !\n", sizeof buffer);
  125. #endif /* !HAVE_NEON */
  126. EXIT:
  127. return (*env)->NewStringUTF(env, buffer);
  128. }

helloneon-intrinsics.h:

  1. #ifndef HELLONEON_INTRINSICS_H
  2. #define HELLONEON_INTRINSICS_H
  3. void fir_filter_neon_intrinsics(short *output, const short* input, const short* kernel, int width, int kernelSize);
  4. #endif /* HELLONEON_INTRINSICS_H */

helloneon-intrinsics.c:

  1. #include "helloneon-intrinsics.h"
  2. #include <arm_neon.h>
  3. /* this source file should only be compiled by Android.mk when targeting
  4. * the armeabi-v7a ABI, and should be built in NEON mode
  5. */
  6. void
  7. fir_filter_neon_intrinsics(short *output, const short* input, const short* kernel, int width, int kernelSize)
  8. {
  9. #if 1
  10. int nn, offset = -kernelSize/2;
  11. for (nn = 0; nn < width; nn++)
  12. {
  13. int mm, sum = 0;
  14. int32x4_t sum_vec = vdupq_n_s32(0);
  15. for(mm = 0; mm < kernelSize/4; mm++)
  16. {
  17. int16x4_t  kernel_vec = vld1_s16(kernel + mm*4);
  18. int16x4_t  input_vec = vld1_s16(input + (nn+offset+mm*4));
  19. sum_vec = vmlal_s16(sum_vec, kernel_vec, input_vec);
  20. }
  21. sum += vgetq_lane_s32(sum_vec, 0);
  22. sum += vgetq_lane_s32(sum_vec, 1);
  23. sum += vgetq_lane_s32(sum_vec, 2);
  24. sum += vgetq_lane_s32(sum_vec, 3);
  25. if(kernelSize & 3)
  26. {
  27. for(mm = kernelSize - (kernelSize & 3); mm < kernelSize; mm++)
  28. sum += kernel[mm] * input[nn+offset+mm];
  29. }
  30. output[nn] = (short)((sum + 0x8000) >> 16);
  31. }
  32. #else /* for comparison purposes only */
  33. int nn, offset = -kernelSize/2;
  34. for (nn = 0; nn < width; nn++) {
  35. int sum = 0;
  36. int mm;
  37. for (mm = 0; mm < kernelSize; mm++) {
  38. sum += kernel[mm]*input[nn+offset+mm];
  39. }
  40. output[nn] = (short)((sum + 0x8000) >> 16);
  41. }
  42. #endif
  43. }

5、 利用NDK生成.so文件:选中工程-->Properties-->Builders-->New-->选中Program-->OK,Name:Hello_Neon_Builder,Location: D:\ProgramFiles\Android\android-sdk\android-ndk-r9\ndk-build.cmd,Working Directory: E:\NEON\Eclipse\Hello-Neon -->Apply,选中Refresh,勾选Refreshresources upon completion, 勾选Specific resources,点击Specify Resources…,勾选Hello-Neon工程下的libs文件夹,Finish-->Apply,选中BuildOptions,勾选Allocate Console(necessary for input), After a “Clean”, During manualbuilds, During auto builds, Specify working set of relevant resources,点击SpecifyResoures…,勾选Hello-Neon工程下的jni文件夹,Finish-->Apply-->OK-->OK,会在libs文件夹下生成libhelloneon.so文件;

6、  选中Hello-Neon,-->Run As-->AndroidApplication,运行结果为:

FIRFilter benchmark:

C version       :282.84 ms

Neon version    :135985 ms(x2.07994 faster)

以上是.c文件的操作步骤,若将.c文件该为.cpp文件,则需改动两个文件:

1、将Android.mk改为:

  1. LOCAL_PATH := $(call my-dir)
  2. include $(CLEAR_VARS)
  3. LOCAL_MODULE    := helloneon
  4. #填写要编译的源文件路径
  5. LOCAL_SRC_FILES := helloneon.cpp helloneon-intrinsics.cpp
  6. #默认包含的头文件路径
  7. LOCAL_C_INCLUDES := \
  8. $(LOCAL_PATH) \
  9. $(LOCAL_PATH)/..
  10. #-g 后面的一系列项目添加了才能使用arm_neon-h头文件, -mfloat-abi=softfp -mfpu=neon 使用arm_neon.h必须
  11. LOCAL_CFLAGS := -g -mfloat-abi=softfp -mfpu=neon -march=armv7-a -mtune=cortex-a8
  12. LOCAL_LDLIBS := -lz -llog
  13. TARGET_ARCH_ABI := armeabi-v7a
  14. LOCAL_ARM_MODE := arm
  15. ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
  16. #采用NEON优化技术
  17. LOCAL_ARM_NEON := true
  18. #LOCAL_CFLAGS := -DHAVE_NEON=1
  19. endif
  20. LOCAL_STATIC_LIBRARIES := cpufeatures
  21. #生成动态调用库
  22. include $(BUILD_SHARED_LIBRARY)
  23. $(call import-module,cpufeatures)

2、helloneon.c改为:

  1. #include <jni.h>
  2. #include <time.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <cpu-features.h>
  6. #include "helloneon-intrinsics.h"
  7. #define DEBUG 0
  8. #define HAVE_NEON
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. #if DEBUG
  13. #include <android/log.h>
  14. #  define  D(x...)  __android_log_print(ANDROID_LOG_INFO,"helloneon",x)
  15. #else
  16. #  define  D(...)  do {} while (0)
  17. #endif
  18. /* return current time in milliseconds */
  19. static double
  20. now_ms(void)
  21. {
  22. struct timespec res;
  23. clock_gettime(CLOCK_REALTIME, &res);
  24. return 1000.0*res.tv_sec + (double)res.tv_nsec/1e6;
  25. }
  26. /* this is a FIR filter implemented in C */
  27. static void
  28. fir_filter_c(short *output, const short* input, const short* kernel, int width, int kernelSize)
  29. {
  30. int  offset = -kernelSize/2;
  31. int  nn;
  32. for (nn = 0; nn < width; nn++) {
  33. int sum = 0;
  34. int mm;
  35. for (mm = 0; mm < kernelSize; mm++) {
  36. sum += kernel[mm]*input[nn+offset+mm];
  37. }
  38. output[nn] = (short)((sum + 0x8000) >> 16);
  39. }
  40. }
  41. #define  FIR_KERNEL_SIZE   32
  42. #define  FIR_OUTPUT_SIZE   2560
  43. #define  FIR_INPUT_SIZE    (FIR_OUTPUT_SIZE + FIR_KERNEL_SIZE)
  44. #define  FIR_ITERATIONS    600
  45. static const short  fir_kernel[FIR_KERNEL_SIZE] = {
  46. 0x10, 0x20, 0x40, 0x70, 0x8c, 0xa2, 0xce, 0xf0, 0xe9, 0xce, 0xa2, 0x8c, 070, 0x40, 0x20, 0x10,
  47. 0x10, 0x20, 0x40, 0x70, 0x8c, 0xa2, 0xce, 0xf0, 0xe9, 0xce, 0xa2, 0x8c, 070, 0x40, 0x20, 0x10 };
  48. static short        fir_output[FIR_OUTPUT_SIZE];
  49. static short        fir_input_0[FIR_INPUT_SIZE];
  50. static const short* fir_input = fir_input_0 + (FIR_KERNEL_SIZE/2);
  51. static short        fir_output_expected[FIR_OUTPUT_SIZE];
  52. /* This is a trivial JNI example where we use a native method
  53. * to return a new VM String. See the corresponding Java source
  54. * file located at:
  55. *
  56. *   apps/samples/hello-neon/project/src/com/example/neon/HelloNeon.java
  57. */
  58. JNIEXPORT jstring JNICALL Java_com_hello_1neon_android_Hello_1NeonProjectActivity_stringFromJNI(JNIEnv *env, jobject thiz)
  59. {
  60. char str[512] = {0};
  61. uint64_t features;
  62. char buffer[512];
  63. char tryNeon = 0;
  64. double  t0, t1, time_c, time_neon;
  65. /* setup FIR input - whatever */
  66. {
  67. int  nn;
  68. for (nn = 0; nn < FIR_INPUT_SIZE; nn++) {
  69. fir_input_0[nn] = (5*nn) & 255;
  70. }
  71. fir_filter_c(fir_output_expected, fir_input, fir_kernel, FIR_OUTPUT_SIZE, FIR_KERNEL_SIZE);
  72. }
  73. /* Benchmark small FIR filter loop - C version */
  74. t0 = now_ms();
  75. {
  76. int  count = FIR_ITERATIONS;
  77. for (; count > 0; count--) {
  78. fir_filter_c(fir_output, fir_input, fir_kernel, FIR_OUTPUT_SIZE, FIR_KERNEL_SIZE);
  79. }
  80. }
  81. t1 = now_ms();
  82. time_c = t1 - t0;
  83. sprintf(str, "FIR Filter benchmark:\nC version          : %g ms\n", time_c);
  84. strlcpy(buffer, str, sizeof buffer);
  85. strlcat(buffer, "Neon version   : ", sizeof buffer);
  86. if (android_getCpuFamily() != ANDROID_CPU_FAMILY_ARM) {
  87. strlcat(buffer, "Not an ARM CPU !\n", sizeof buffer);
  88. goto EXIT;
  89. }
  90. features = android_getCpuFeatures();
  91. if ((features & ANDROID_CPU_ARM_FEATURE_ARMv7) == 0) {
  92. strlcat(buffer, "Not an ARMv7 CPU !\n", sizeof buffer);
  93. goto EXIT;
  94. }
  95. /* HAVE_NEON is defined in Android.mk ! */
  96. #ifdef HAVE_NEON
  97. if ((features & ANDROID_CPU_ARM_FEATURE_NEON) == 0) {
  98. strlcat(buffer, "CPU doesn't support NEON !\n", sizeof buffer);
  99. goto EXIT;
  100. }
  101. /* Benchmark small FIR filter loop - Neon version */
  102. t0 = now_ms();
  103. {
  104. int  count = FIR_ITERATIONS;
  105. for (; count > 0; count--) {
  106. fir_filter_neon_intrinsics(fir_output, fir_input, fir_kernel, FIR_OUTPUT_SIZE, FIR_KERNEL_SIZE);
  107. }
  108. }
  109. t1 = now_ms();
  110. time_neon = t1 - t0;
  111. sprintf(str, "%g ms (x%g faster)\n", time_neon, time_c / (time_neon < 1e-6 ? 1. : time_neon));
  112. strlcat(buffer, str, sizeof buffer);
  113. /* check the result, just in case */
  114. {
  115. int  nn, fails = 0;
  116. for (nn = 0; nn < FIR_OUTPUT_SIZE; nn++) {
  117. if (fir_output[nn] != fir_output_expected[nn]) {
  118. if (++fails < 16)
  119. D("neon[%d] = %d expected %d", nn, fir_output[nn], fir_output_expected[nn]);
  120. }
  121. }
  122. D("%d fails\n", fails);
  123. }
  124. #else /* !HAVE_NEON */
  125. strlcat(buffer, "Program not compiled with ARMv7 support !\n", sizeof buffer);
  126. #endif /* !HAVE_NEON */
  127. EXIT:
  128. return env->NewStringUTF(buffer);
  129. }
  130. #ifdef __cplusplus
  131. }
  132. #endif

参考文献:

1、  http://blog.csdn.net/fengbingchun/article/details/11580983

2、  android-ndk-r9-windows-x86_64中的hello-neon例子代码

NEON在Android中的使用举例【转】的更多相关文章

  1. ZT onActivityResult在android中的用法

    onActivityResult在android中的用法 举例说我想要做的一个事情是,在一个主界面(主Activity)上能连接往许多不同子功能模块(子Activity上去),当子模块的事情做完之后就 ...

  2. Android中的关于MDM中的几个方法举例

    Android中的关于MDM中的几个方法举例 首先介绍一下MDM是什么的缩写,MDM是什么? MDM 是 (Mobile Device Management )的缩写,中文翻译过来就是移动设备管理.随 ...

  3. Android中悬浮窗口

    调用WindowManager,并设置WindowManager.LayoutParams的相关属性,通过WindowManager的addView方法创建View,这样产生出来的View根据Wind ...

  4. Android中ListView 控件与 Adapter 适配器如何使用?

    一个android应用的成功与否,其界面设计至关重要.为了更好的进行android ui设计,我们常常需要借助一些控件和适配器.今天小编在android培训网站上搜罗了一些有关ListView 控件与 ...

  5. Android中的单位及测试相关概念

    android中的单位: in 英寸 pt 点距 px 像素  dp(dip) 密度无关的像素单位,自适应device屏幕的比例,通常涉及长宽高时采用 sp 与范围无关的像素单位,通常在设置字体大小时 ...

  6. Android中的SQLite使用学习

    Android中的SQLite使用学习 SQLite是非常流行的嵌入式关系型数据库,轻载, 速度快,而且是开源.在Android中,runtime提供SQLite,所以我们可以使用SQLite,而且是 ...

  7. Android中Handler作用

    在Android的UI开发中,我们经常会使用Handler来控制主UI程序的界面变化.有关Handler的作用,我们总结为:与其他线程协同工作,接收其他线程的消息并通过接收到的消息更新主UI线程的内容 ...

  8. Android中的动画学习总结

    android中动画可分为三种:帧动画,补间动画,和属性动画.其中属性动画是google推荐的,它可以实现前面两种动画的效果,运用起来更加灵活. 帧动画:顾名思义,就是一帧一帧的图片,快速播放形成的动 ...

  9. 【转】Android中自定义控件的步骤

    原文网址:http://blog.csdn.net/lianchen/article/details/48038969 Android开发中难免遇到需要自定义控件的需求,有些是产品的要求在Androi ...

随机推荐

  1. 腾讯企鹅智酷100多张PPT:移动时代创业黄金法则

    移动时代创业黄金法则 http://tech.qq.com/a/20141223/008325.htm#p=8

  2. 离线下载Windows 调试符号 Symbols

    公司开发机没有不能连接到互联网.调试程序时那些Windows模块(如ntdll.dll)不能加载符号,而程序总是崩在这些模块里.想看一眼到底崩在了什么地方. 需要把对应的符号下载下来. 使用工具sym ...

  3. C#线程系列讲座(4):同步与死锁

    虽然线程可以在一定程度上提高程序运行的效率,但也会产生一些副作用.让我们先看看如下的代码:     class Increment     {         private int n = 0;   ...

  4. ios-chart 不支持渐变的底色 --- 后面支持了渐变

    https://github.com/danielgindi/ios-charts/issues/186 后话,最近库更新了,可以支持渐变色

  5. 针对某个数据库error做systemstate dump

    如果想对某个具体error做systemstate dump收集,可以借助event来实现. 例如想在数据库遇到ora-00054时,收集数据systemstate dump信息: 开启: sqlpl ...

  6. 仅使用处理单个数字的I/O例程,编写一个过程以输出任意实数(可以是负的)

    题目取自:<数据结构与算法分析:C语言描述_原书第二版>——Mark Allen Weiss   练习1.3 如题. 补充说明:假设仅有的I/O例程只处理单个数字并将其输出到终端,我们将这 ...

  7. iOS缓存使用的框架

    MagicalRecord  FMDB 都可以在gitHub上找到

  8. NSMutableDictionary中元素替换

    NSMutableDictionary *dic = [NSMutableDictionary new]; [dic addEntriesFromDictionary:@{@"key&quo ...

  9. 新建一个Activity通过按钮打开它,再通过按钮关闭它

    首先需要创建一个供打开和关闭的Activity,先在scr下当前项目的包中创建一个新类Activity1, 并选择让其继承自Activity类,如下图所示: 之后配置AndroidMainifest. ...

  10. ruby初步学习中遇到的错误

    print <<off This is the second way of creating here document ie. multiple line string; off 报错: ...