allocate.c
来自「多目标遗传算法的程序」· C语言 代码 · 共 65 行
C
65 行
/* 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) { ind->xreal = (long double *)malloc(nreal*sizeof(long double)); } ind->obj = (long double *)malloc(nobj*sizeof(long double)); if (ncon != 0) { ind->constr = (long double *)malloc(ncon*sizeof(long double)); } 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); } free(ind->obj); if (ncon != 0) { free(ind->constr); } return;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?