📄 allocate.c
字号:
/* 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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -