1 /****************************************************************************
2     Copyright (C) 1987-2015 by Jeffery P. Hansen
3 
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8 
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13 
14     You should have received a copy of the GNU General Public License along
15     with this program; if not, write to the Free Software Foundation, Inc.,
16     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 ****************************************************************************/
18 #ifndef __ycmalloc_h
19 #define __ycmalloc_h
20 
21 /*
22    Allignment type for memory allocation
23 */
24 #define ALGN_BYTE	sizeof(char)		/* Byte alligned allocation */
25 #define ALGN_SHORT	sizeof(short)		/* Short word alligned allocation */
26 #define ALGN_WORD	sizeof(int)		/* Standard word alligned allocation */
27 #define ALGN_LONG	sizeof(long)		/* Long word alligned allocation */
28 #define ALGN_FLOAT	sizeof(float)		/* Double word alligned allocation */
29 #define ALGN_DOUBLE	sizeof(double)		/* Double word alligned allocation */
30 
31 #ifndef YC_POOL_SIZE
32 #define YC_POOL_SIZE 16384		/* Block size for malloc pool */
33 #endif
34 
35 /*
36   Management functions
37 */
38 void yc_setup();			/* Guarantee at least one memory pool on stack */
39 void yc_freeall();			/* Flush the top memory pool on stack */
40 void yc_pushpool();			/* Create a new memory temporary memory area */
41 void yc_poppool();			/* Delete the top temporary memory area */
42 
43 /*
44   Allocation functions
45 */
46 char *yc_strdup(const char *S);		/* Duplicate string on temporary memory pool */
47 void *yc_malloc(long L,int A);		/* Allocate memory on temporary memory pool */
48 char *yc_sprintf(char *s,...);		/* Concatenate a bunch of strings */
49 void *yc_calloc(long N,long S,int Algn);
50 void *yc_realloc(void *P,long oldL,long L,int Algn);
51 
52 /*
53    Allocate memory for an object of type T from the yc temporary pool
54 */
55 #define ycnew(T) (T*) yc_malloc(sizeof(T),ALGN_WORD)
56 #define ycvnew(T,n) (T*) yc_malloc((n)*sizeof(T),ALGN_WORD)
57 
58 #endif
59