1 /**
2  ** allocate.h ---- common ground for malloc & friends in 16 & 32 bit envs
3  **                 stack based temporary memory allocation
4  **
5  ** Copyright (c) 1995 Csaba Biegl, 820 Stirrup Dr, Nashville, TN 37221
6  ** [e-mail: csaba@vuse.vanderbilt.edu]
7  **
8  ** This file is part of the GRX graphics library.
9  **
10  ** The GRX graphics library is free software; you can redistribute it
11  ** and/or modify it under some conditions; see the "copying.grx" file
12  ** for details.
13  **
14  ** This library is distributed in the hope that it will be useful,
15  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17  **
18  **/
19 
20 #if defined(__alpha__) || (GRX_VERSION==GRX_VERSION_GENERIC_X11) && !defined(_AIX)
21 #  include <stdlib.h>
22 #elif defined(__TURBOC__)
23 #  include <alloc.h>
24 #  include "bcc/allocate.h"
25 #elif defined(__WATCOMC__)
26 #  include <stdlib.h>
27 #elif defined(_MSC_VER) && defined(_WIN32)
28 #  include <stdlib.h>
29 #elif defined(__MINGW32__) && !defined(alloca)
30 #  define alloca __builtin_alloca
31 #else
32 #  include <stdlib.h>
33 #endif
34 
35 #if defined(_MSC_VER) && !defined(_WIN32)
36 #define farmalloc  _fmalloc
37 #define farrealloc _frealloc
38 #define farcalloc  _fcalloc
39 #define farfree    _ffree
40 #elif !defined(__TURBOC__)
41 #define farmalloc  malloc
42 #define farrealloc realloc
43 #define farcalloc  calloc
44 #define farfree    free
45 #endif
46 
47 #if 0 && defined(_MSC_VER)
48 #define setup_alloca() do { unsigned char _stack_dummy_var_ = '\001'
49 #define reset_alloca() } while (0)
50 #endif
51 
52 
53 #ifndef setup_alloca
54 #define setup_alloca()
55 #define reset_alloca()
56 #endif
57 
58 /* ALLOC / FREE : use alloca if possible */
59 #ifdef SMALL_STACK
60 #define ALLOC(sze) malloc(sze)
61 #define FREE(p)    free(p)
62 #define setup_ALLOC()
63 #define reset_ALLOC()
64 #elif defined(_MSC_VER) && !defined(_WIN32)
65 #define ALLOC(sze) _alloca(sze)
66 #define FREE(p)
67 #define setup_ALLOC  setup_alloca
68 #define reset_ALLOC  reset_alloca
69 #else
70 #define ALLOC(sze) alloca(sze)
71 #define FREE(p)
72 #define setup_ALLOC  setup_alloca
73 #define reset_ALLOC  reset_alloca
74 #endif
75 
76 /* temp buffer for blits etc. */
77 extern void far *_GrTempBuffer;
78 extern unsigned  _GrTempBufferBytes;
79 #define _GrTempBufferAlloc(b) (                                     \
80     ((unsigned)(b) <= _GrTempBufferBytes) ? _GrTempBuffer           \
81 					  : _GrTempBufferAlloc_(b) )
82 extern void far *_GrTempBufferAlloc_(size_t bytes);
83 extern void _GrTempBufferFree(void);
84