tre_mem.hpp
00001 #line 6930 "./lpsrc/tre.pak"
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef TRE_MEM_H
00023 #define TRE_MEM_H 1
00024
00025 #include <stdlib.h>
00026
00027 #define TRE_MEM_BLOCK_SIZE 1024
00028
00029 typedef struct tre_list {
00030 void *data;
00031 struct tre_list *next;
00032 } tre_list_t;
00033
00034 typedef struct tre_mem_struct {
00035 tre_list_t *blocks;
00036 tre_list_t *current;
00037 char *ptr;
00038 size_t n;
00039 int failed;
00040 void **provided;
00041 } *tre_mem_t;
00042
00043
00044 tre_mem_t tre_mem_new_impl(int provided, void *provided_block);
00045 void *tre_mem_alloc_impl(tre_mem_t mem, int provided, void *provided_block,
00046 int zero, size_t size);
00047
00048
00049 #define tre_mem_new() tre_mem_new_impl(0, NULL)
00050
00051
00052
00053 #define tre_mem_alloc(mem, size) tre_mem_alloc_impl(mem, 0, NULL, 0, size)
00054
00055
00056
00057
00058 #define tre_mem_calloc(mem, size) tre_mem_alloc_impl(mem, 0, NULL, 1, size)
00059
00060 #ifdef TRE_USE_ALLOCA
00061
00062
00063
00064 #define tre_mem_newa() \
00065 tre_mem_new_impl(1, alloca(sizeof(struct tre_mem_struct)))
00066
00067 #define tre_mem_alloca(mem, size) \
00068 ((mem)->n >= (size) \
00069 ? tre_mem_alloc_impl((mem), 1, NULL, 0, (size)) \
00070 : tre_mem_alloc_impl((mem), 1, alloca(TRE_MEM_BLOCK_SIZE), 0, (size)))
00071 #endif
00072
00073
00074
00075 void tre_mem_destroy(tre_mem_t mem);
00076
00077 #endif
00078
00079