📄 alloc.h
字号:
/*******dynamic memory allocation**********************/
complex *CMPLX_Vector(nh)
/* Allocates a complex vector with range [0...nh-1] */
int nh;
{
complex *v;
v=(complex *)malloc((unsigned) nh*sizeof(complex));
if (v==NULL) {printf("Unable to allocate memory");}
return v;
}
double *FLOAT_Vector(nh)
/* Allocates a double vector with range [0 ... nh-1] */
int nh;
{
double *v;
v=(double *)malloc((unsigned) nh*sizeof(double));
return v;
}
int *INT_Vector(nh)
/* Allocates an int vector with range [0 ... nh-1] */
int nh;
{
int *v;
v=(int *)malloc((unsigned) nh*sizeof(int));
return v;
}
double **FLOAT_Matrix(row,column)
/*Allocates a double matrix with range [0..rw-1][0..cl-1]*/
int row,column;
{
int i;double **m;
m=(double **) malloc((unsigned) row*sizeof(double*));
for(i=0;i<row;i++)
{m[i]=(double *) malloc((unsigned) column*sizeof(double));}
return m;
}
int **INT_Matrix(row,column)
/*Allocates an int matrix with range [0..rw-1][0..cl-1]*/
int row,column;
{
int i;int **m;
m=(int **) malloc((unsigned) row*sizeof(int));
for(i=0;i<row;i++)
{m[i]=(int *) malloc((unsigned) column*sizeof(int));}
return m;
}
complex **CMPLX_Matrix(row,column)
/*Allocates a complex matrix with range [0..rw-1][0..cl-1] */
int row,column;
{
int i;complex **m;
m=(complex **) malloc((unsigned) row*sizeof(complex*));
for(i=0;i<row;i++)
{m[i]=(complex *) malloc((unsigned) column*sizeof(complex));}
return m;
}
double ***FLOAT_Matrix2(row,column,width)
int row,column,width;
{
int i,j;double ***m;
m=(double ***) malloc((unsigned) row*sizeof(double**));
for(i=0;i<row;i++)
{
m[i]=(double **) malloc((unsigned) column*sizeof(double*));
for(j=0;j<column;j++)
{m[i][j]=(double *) malloc((unsigned) width*sizeof(double));}
}
return m;
}
int ***INT_Matrix2(row,column,width)
int row,column,width;
{
int i,j;int ***m;
m=(int ***) malloc((unsigned) row*sizeof(int**));
for(i=0;i<row;i++)
{
m[i]=(int **) malloc((unsigned) column*sizeof(int*));
for(j=0;j<column;j++)
{m[i][j]=(int *) malloc((unsigned) width*sizeof(int));}
}
return m;
}
void free_INT_Vector(v,nh)
int *v;
int nh;
{free((char *) v);}
void free_CMPLX_Vector(v,nh)
complex *v;
int nh;
{free((char *) v);}
void free_FLOAT_Vector(v,nh)
double *v;
int nh;
{free((char *) v);}
void free_INT_Matrix(m,row,column)
int **m;
int row,column;
{
int i;
for(i=row-1;i>=0;i--) free((char*) m[i]);
free((char*) m);
}
void free_FLOAT_Matrix(m,row,column)
double **m;
int row,column;
{
int i;
for(i=row-1;i>=0;i--) free((char*) m[i]);
free((char*) m);
}
void free_CMPLX_Matrix(m,row,column)
complex **m;
int row,column;
{
int i;
for(i=row-1;i>=0;i--) free((complex*) m[i]);
free((complex*) m);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -