📄 malloc~1.rea
字号:
###########################################################
Information on file: malloc4.c
Written by Xavier Bouyssounouse.
###########################################################
Routines in this file dynamically allocate and free up
multi-dimensional arrays. The main advantage of
these routines over using fixed size arrays is that only
the amount of memory required is allocated, and then
freed when no longer needed. Additionaly, the dimensions
of the arrays need not be passed as parameters to
functions since the dimensions are hidden in the memory
allocated. Another advantage over fixed size arrays
is that the memory allocated by these mallocn routines
is not necessarily contiguous, thus allowing the compiler
to grab available memory wherever it may find it. On
the mac, for example, more than 32k cannot be allocated
contiguously. Thus, a fixed size array of 500X100 cannot
be allocated on the mac yet a variable size array with
these dimensions allocated by the mallocn routines in
this file is permited. A similar problem exists
on the suns.
###########################################################
Information on malloc2(),malloc3(),malloc4().
___________________________________________________________
These routines dynamically allocate 2,3,4 dimensional
arrays of unsigned char. For example, you can allocate an
array of integers of size 5X6X7 as follows:
int ***int_array;
int_array= (int ***) malloc3(5,6,7*sizeof(int));
###########################################################
Information on free2(),free3(),free4().
___________________________________________________________
These routines free up the memory dynamically allocated
by the mallocn routines. For example, to free up the
integer array allocated above, simply enter.
free3((unsigned char **)int_array);
Note: free3(int_array) will generally work also.
###########################################################
Information on getsize2(), getsize3(), getsize4().
___________________________________________________________
These routines determine the size of the input arrays.
For example, to determine the size of the integer array
allocated above, type:
int ***int_image,num_imgs,num_rows,num_cols;
...
getsize2(int_image,&num_imgs,&num_rows,&num_cols);
num_cols/= sizeof(int);
###########################################################
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -