6.1学习内容 ndk编程释放内存,C语言中char*添加字符得方法,java二维数组的读取与生成

ndk的内存释放:

//回收
                (*env)->ReleaseIntArrayElements(env,value, codeLineArray,0);
                (*env)->ReleaseIntArrayElements(env,(jintArray)codeLineArray, codeLineData,0);

                (*env)->DeleteLocalRef(env, value);
                (*env)->DeleteLocalRef(env, codeLineArray);
                (*env)->DeleteLocalRef(env, codeLineData);

                value=NULL;
                codeLineArray = NULL;
                codeLineData=NULL;

往一个string添加char的方法:

//init    
char *ret = malloc(1);
strcpy(ret, "");
//add char
char addchar[]={'\n'};
strcat(ret, addchar);


java二维数组的读取与生成

读取

 jintArray textBinArr = (jintArray)(*env)->CallObjectMethod(env,code,valueGetMethod,firstKey);
    int codeHeight = (*env)->GetArrayLength(env, textBinArr);
    LOGI("codeHeight:%d",codeHeight);

    int picHeight = (*env)->GetArrayLength(env, pic);
    LOGI("picHeight==%d",picHeight);

for (i = 0; i < picHeight; i+=picHeight) {
        jarray lineArray = ((*env)->GetObjectArrayElement(env, pic, i));
        int picWidth =  (*env)->GetArrayLength(env, lineArray);
        jboolean *lineData = (*env)->GetBooleanArrayElements(env, (jbooleanArray)lineArray, 0 );
        for (j=0;j<picWidth;) {
        	//[i][j]=lineData[j]
        }
}
生成:

   //new boolean[][]
    jobjectArray ret;
    jclass boolArrCls = (*env)->FindClass(env, "[Z");
    if ( NULL== boolArrCls) {
        return NULL;
    }

    ret = (*env)->NewObjectArray(env, info.height , boolArrCls, NULL);
    jboolean tmp[info.width];//固定数组,测试用,注意别溢出

    for (int i=0 to 100) {
	jbooleanArray boolArr = (*env)->NewBooleanArray(env,width);

	for (j 0 to 1000) {
		tem[j]=randonInt();


	}
	(*env)->SetBooleanArrayRegion(env,boolArr, 0, width, tmp);
               (*env)->SetObjectArrayElement(env,ret, y, boolArr);
               (*env)->DeleteLocalRef(env,boolArr);

    }






吐槽一下今天:

几个20多岁的朋友都想过6.1,是不是脑子都抽水了?

NDK代码量比java多了好多;

打算去北京,好多人反对;

还没女朋友~









你可能感兴趣的:(android,NDK)