allocate.c
来源:互联网 发布:burpsuite安装linux 编辑:程序博客网 时间:2024/06/17 05:10
/* Memory allocation and deallocation routines */# include <stdio.h># include <stdlib.h># include <math.h># include "global.h"# include "rand.h"/* Function to allocate memory to a population */void allocate_memory_pop (population *pop, int size){ int i; pop->ind = (individual *)malloc(size*sizeof(individual)); for (i=0; i<size; i++) { allocate_memory_ind (&(pop->ind[i])); } return;}/* Function to allocate memory to an individual */void allocate_memory_ind (individual *ind){ int j; if (nreal != 0)//nreal is a global variable,is the number of "real variables" { ind->xreal = (double *)malloc(nreal*sizeof(double)); } if (nbin != 0)//nbin is a global variable, is the number of "binary variables" { ind->xbin = (double *)malloc(nbin*sizeof(double)); ind->gene = (int **)malloc(nbin*sizeof(int *)); for (j=0; j<nbin; j++) { ind->gene[j] = (int *)malloc(nbits[j]*sizeof(int));//nbits is an arrary of "nbin*(double)",and nbits[j] is initialized in main func(nsga2r.c) } } ind->obj = (double *)malloc(nobj*sizeof(double));//nobj is a global variable, is the number of objectives if (ncon != 0) { ind->constr = (double *)malloc(ncon*sizeof(double));//ncon is a global variable, is the number of constraints } return;}/* Function to deallocate memory to a population */void deallocate_memory_pop (population *pop, int size){ int i; for (i=0; i<size; i++) { deallocate_memory_ind (&(pop->ind[i])); } free (pop->ind); return;}/* Function to deallocate memory to an individual */void deallocate_memory_ind (individual *ind){ int j; if (nreal != 0) { free(ind->xreal); } if (nbin != 0) { for (j=0; j<nbin; j++) { free(ind->gene[j]); } free(ind->xbin); free(ind->gene); } free(ind->obj); if (ncon != 0) { free(ind->constr); } return;}
源代码来源:http://www.iitk.ac.in/kangal/codes.shtml中间添加了一些自己的注释,用下划线标识的。
(其实就是一些可以用SI查找一下啊就能找到这些变量的含义。只是希望记下来印象深刻一些吧。)
0 0
- allocate.c
- sgi allocate
- gsl: rng.c:46: ERROR: failed to allocate space for rng state
- c 语言中内存的动态分配(allocate)和释放(free)
- Question 11: Which of the following statements describe the result when standard new cannot allocate the requested storage in C+
- Allocate aligned memory
- 什么是write-allocate policy?
- STL stack allocate
- Memory allocate in Ogre
- MPI_Probe-Dynamically allocate memory
- Allocate exception for…
- 动态数组new、allocate
- ByteBuffer.allocate()、BufferUnderflowException Android
- Hadoop allocate big file
- Android cannot allocate memory
- write-allocate policy
- 什么是write-allocate policy?
- 什么是write-allocate policy?
- JSP中EL表达式以及JSTL标签库
- CentOS7 PXE安装批量安装操作系统
- mathematica中二维表达式的输入
- Java Object类的public方法
- 【HDU5900】【区间DP】QSC and master 题解
- allocate.c
- 完全二叉树的叶子节点总数问题
- 【J2SE】——异常实践篇
- 新年第一周
- Android 仪表盘动画
- C/C++中cin.get()的用法与EOF的使用
- 刮奖效果
- Log4net入门使用
- A1021. Deepest Root (25)