⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 buffalloc.c

📁 su 的源代码库
💻 C
字号:
/* Copyright (c) Colorado School of Mines, 2006.*//* All rights reserved.                       *//*********************** self documentation **********************//*************************************************************************BUFFALLOC - routines to ALLOCate/initialize and free BUFFersbuffAlloc1      allocate a 1D bufferbuffRealloc1    reallocate a 1D bufferbuffFree1       free a 1D bufferbuffAlloc2      allocate a 2D bufferbuffFree2       free a 2D buffer**************************************************************************Function Prototypes:memBUFF *buffAlloc1(int n);void buffRealloc1(memBUFF *buff, int n);void buffFree1(memBUFF *buff);memBUFF **buffAlloc2(int n1, int n2);void buffFree2(memBUFF **buff, int n1);**************************************************************************buffAlloc1:Input:n	size of bufferReturns:pointer to type memBUFFbuffRealloc1:Input:buff	pointer to buffern	new size of bufferbuffFree1:Input:buff	pointer to bufferbuffAlloc2:Input:n1	 size of buffer in fast dimensionn2	 size of buffer in slow dimensionReturns:pointer to type memBUFF**************************************************************************Author:      Tong Chen*************************************************************************//**************** end self doc ********************************/#include "comp.h"memBUFF *buffAlloc1(int n)/*************************************************************************allocate a 1D  buffer of size n and initialize*************************************************************************/{	memBUFF *buff;	buff = (memBUFF *) malloc(sizeof(memBUFF));	buff->code = (unsigned char *) malloc(n*sizeof(char));	/* init the position and bound */	buff->mbound = n;	buff->pos = 0;	return (buff);}void buffRealloc1(memBUFF *buff, int n)/*************************************************************************reallocate a 1D buffer of size to n and set the position to end of bufferif n is less than buff->pos *************************************************************************/{	unsigned char *code;		code = buff->code;	buff->code = (unsigned char *) realloc(code, n*sizeof(char));	/* modify the bound */	buff->mbound = n;	buff->pos = (buff->pos > n)? n : buff->pos;}void buffFree1(memBUFF *buff)/*************************************************************************free a 1D buffer*************************************************************************/{	free((void *) buff->code);	free((void *) buff);}memBUFF **buffAlloc2(int n1, int n2)/*************************************************************************allocate an array[n1] of buffers each with size n2 and initialize*************************************************************************/{	memBUFF **buff;	int i;	buff = (memBUFF **) malloc(n1*sizeof(memBUFF *));	/* the buffers do not have to be consective */	for(i=0; i<n1; i++) 	    buff[i] = (memBUFF *) buffAlloc1(n2);	return (buff);}void buffFree2(memBUFF **buff, int n1)/*************************************************************************free a 2D buffer*************************************************************************/{	int i;	for(i=0; i<n1; i++)	    buffFree1((void *) buff[i]);		free(buff);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -