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

📄 wpcbuffal.c

📁 su 的源代码库
💻 C
字号:
/* Copyright (c) Colorado School of Mines, 2006.*//* All rights reserved.                       *//* WPCBUFFAL: $Revision: 1.2 $ ; $Date: 1997/01/10 22:28:41 $	*//*********************** self documentation **********************//*************************************************************************WPCBUFFAL - routines to allocate/initialize and free buffersbuffAlloc1 - allocate a 1D  buffer of size n and initializebuffRealloc1 - reallocate a 1D buffer of size to n and set the 		position to end of buffer if n is less than buff->pos buffFree1 -  free a 1D bufferbuffAlloc2 - allocate an array[n1] of buffers each with size n2 and		initializebuffFree2 -  free a 2D buffer*************************************************************************Function Prototypes:void *buffAlloc1(int n)void buffRealloc1(void *inbuff, int n)void buffFree1(void *inbuff)void **buffAlloc2(int n1, int n2)void buffFree2(void **inbuff, int n1)*************************************************************************buffAlloc1:Input:n		size of bufferReturn:pointer to (void *)buffRealloc1:Input:inbuff		buffer to be reallocatedn		new sizebuffFree1:Input:inbuff		buffer to be freedbuffAlloc2:n1		number of buffers in the arrayn2		size of each bufferbuffFree2:inbuff		buffer array to be freedn1		number of buffers to be freed*************************************************************************Author: CWP: Tong Chen, 1994*************************************************************************//**************** end self doc ********************************/#include "wpc.h"#include "wpclib.h"void *buffAlloc1(int n)/*************************************************************************allocate a 1D  buffer of size n and initialize*************************************************************************/{	wpcBUFF *buff;	buff = (wpcBUFF *) malloc(sizeof(wpcBUFF));	buff->code = (unsigned char *) malloc(n*sizeof(char));	/* init the position and bound */	buff->mbound = n;	buff->pos = 0;	return ((void *)buff);}void buffRealloc1(void *inbuff, int n)/*************************************************************************reallocate a 1D buffer of size to n and set the position to end of bufferif n is less than buff->pos *************************************************************************/{	wpcBUFF *buff = (wpcBUFF *) inbuff;	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(void *inbuff)/*************************************************************************free a 1D buffer*************************************************************************/{	wpcBUFF *buff = (wpcBUFF *) inbuff;	free((void *) buff->code);	free((void *) buff);}void **buffAlloc2(int n1, int n2)/*************************************************************************allocate an array[n1] of buffers each with size n2 and initialize*************************************************************************/{	wpcBUFF **buff;	int i;	buff = (wpcBUFF **) malloc(n1*sizeof(wpcBUFF *));	/* the buffers do not have to be consective */	for(i=0; i<n1; i++) 	    buff[i] = (wpcBUFF *) buffAlloc1(n2);	return ((void **)buff);}void buffFree2(void **inbuff, int n1)/*************************************************************************free a 2D buffer*************************************************************************/{	wpcBUFF **buff = (wpcBUFF **) inbuff;	int i;	for(i=0; i<n1; i++)	    buffFree1((void *) buff[i]);		free((void **) buff);}

⌨️ 快捷键说明

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