1 /* $Id$ $Revision$ */ 2 /* vim:set shiftwidth=4 ts=8: */ 3 4 /************************************************************************* 5 * Copyright (c) 2011 AT&T Intellectual Property 6 * All rights reserved. This program and the accompanying materials 7 * are made available under the terms of the Eclipse Public License v1.0 8 * which accompanies this distribution, and is available at 9 * http://www.eclipse.org/legal/epl-v10.html 10 * 11 * Contributors: See CVS logs. Details at http://www.graphviz.org/ 12 *************************************************************************/ 13 14 #ifndef GV_MEMORY_H 15 #define GV_MEMORY_H 16 17 #include <stdlib.h> 18 #ifdef HAVE_MALLOC_H 19 #include <malloc.h> 20 #endif 21 22 #ifdef __cplusplus 23 extern "C" { 24 #endif 25 26 #define NEW(t) (t*)zmalloc(sizeof(t)) 27 #define N_NEW(n,t) (t*)gcalloc((n),sizeof(t)) 28 #define GNEW(t) (t*)gmalloc(sizeof(t)) 29 30 #define N_GNEW(n,t) (t*)gcalloc((n),sizeof(t)) 31 #define N_GGNEW(n,t) (t*)calloc((n),sizeof(t)) 32 #define ALLOC(size,ptr,type) (ptr? (type*)grealloc(ptr,(size)*sizeof(type)):(type*)gmalloc((size)*sizeof(type))) 33 #define RALLOC(size,ptr,type) ((type*)grealloc(ptr,(size)*sizeof(type))) 34 #define ZALLOC(size,ptr,type,osize) (ptr? (type*)zrealloc(ptr,size,sizeof(type),osize):(type*)zmalloc((size)*sizeof(type))) 35 #ifdef GVDLL 36 #define extern __declspec(dllexport) 37 #else 38 #ifdef _WIN32 39 #ifndef GVC_EXPORTS 40 #define extern __declspec(dllimport) 41 #endif 42 #endif 43 44 #endif 45 46 extern void *zmalloc(size_t); 47 extern void *zrealloc(void *, size_t, size_t, size_t); 48 extern void *gcalloc(size_t nmemb, size_t size); 49 extern void *gmalloc(size_t); 50 extern void *grealloc(void *, size_t); 51 #undef extern 52 53 #ifdef __cplusplus 54 } 55 #endif 56 57 #endif 58