00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef CU_SCRATCH_H
00019 #define CU_SCRATCH_H
00020
00021 #include <cu/fwd.h>
00022
00023 CU_BEGIN_DECLARATIONS
00024
00025
00026
00027
00028
00029
00030
00031 typedef struct cu_scratch *cu_scratch_t;
00032
00033
00034 struct cu_scratch
00035 {
00036 size_t size;
00037 void *ptr;
00038 };
00039
00040
00041
00042 #define CU_SCRATCH_INIT { 0, NULL }
00043
00044
00045 CU_SINLINE void
00046 cu_scratch_init(cu_scratch_t scr) { scr->size = 0; scr->ptr = NULL; }
00047
00048
00049 CU_SINLINE size_t cu_scratch_size(cu_scratch_t scr) { return scr->size; }
00050
00051
00052 CU_SINLINE void *cu_scratch_ptr(cu_scratch_t scr) { return scr->ptr; }
00053
00054 void cuP_scratch_alloc_min(cu_scratch_t, size_t);
00055 void cuP_scratch_alloc_log(cu_scratch_t, size_t);
00056 void cuP_scratch_realloc_min(cu_scratch_t, size_t);
00057 void cuP_scratch_realloc_log(cu_scratch_t, size_t);
00058
00059
00060
00061 CU_SINLINE void *
00062 cu_scratch_alloc_min(cu_scratch_t scr, size_t size)
00063 {
00064 if (scr->size < size)
00065 cuP_scratch_alloc_min(scr, size);
00066 return scr->ptr;
00067 }
00068
00069
00070
00071
00072 CU_SINLINE void *
00073 cu_scratch_alloc_log(cu_scratch_t scr, size_t size)
00074 {
00075 if (scr->size < size)
00076 cuP_scratch_alloc_log(scr, size);
00077 return scr->ptr;
00078 }
00079
00080
00081 CU_SINLINE void *
00082 cu_scratch_realloc_min(cu_scratch_t scr, size_t size)
00083 {
00084 if (scr->size < size)
00085 cuP_scratch_realloc_min(scr, size);
00086 return scr->ptr;
00087 }
00088
00089
00090 CU_SINLINE void *
00091 cu_scratch_realloc_log(cu_scratch_t scr, size_t size)
00092 {
00093 if (scr->size < size)
00094 cuP_scratch_realloc_log(scr, size);
00095 return scr->ptr;
00096 }
00097
00098
00099 #define cu_scratch_cct cu_scratch_init
00100
00101
00102 CU_END_DECLARATIONS
00103
00104 #endif