00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef __UT_StackAlloc__
00019 #define __UT_StackAlloc__
00020
00021 #include "UT_Assert.h"
00022
00023 #ifdef WIN32
00024 #include <malloc.h>
00025 #else
00026 #if defined(LINUX) || defined(MBSD)
00027 #include <stdlib.h>
00028 #else
00029 #include <alloca.h>
00030 #endif
00031 #endif
00032
00033
00034
00035 #define UT_STACK_LIMIT 131072
00036
00037
00038 #define UT_STACK_ALLOCA 100
00039 #define UT_STACK_MALLOC 200
00040
00041 #define UTstackAlloc(size) (void *)(&((size < UT_STACK_LIMIT) ? \
00042 (*((int32 *)::alloca(size+2*sizeof(int32))) = UT_STACK_ALLOCA) : \
00043 (*((int32 *)::malloc(size+2*sizeof(int32))) = UT_STACK_MALLOC)) + 2)
00044
00045 #define UTstackFree(ptr) \
00046 { \
00047 UT_ASSERT_P(*((int32 *)ptr - 2) == UT_STACK_MALLOC || \
00048 *((int32 *)ptr - 2) == UT_STACK_ALLOCA); \
00049 if (*((int32 *)ptr - 2) == UT_STACK_MALLOC) \
00050 ::free(((int32 *)ptr - 2)); \
00051 }
00052
00053 #endif