24 #ifndef _MEMORY_ALLOC_H_ 25 #define _MEMORY_ALLOC_H_ 37 #include <sys/types.h> 44 #if defined (__cplusplus) 50 #define CEIL_PTVDIV(dividend, divisor) \ 51 (((dividend) == 0) ? 0 : (((dividend) - 1) / (divisor)) + 1) 54 #define DB_SIZEOF(val) (sizeof(val)) 59 #define CHAR_ALIGNMENT sizeof(char) 60 #define SHORT_ALIGNMENT sizeof(short) 61 #define INT_ALIGNMENT sizeof(int) 62 #define LONG_ALIGNMENT sizeof(long) 63 #define FLOAT_ALIGNMENT sizeof(float) 64 #define DOUBLE_ALIGNMENT sizeof(double) 66 #define PTR_ALIGNMENT 4 68 #define PTR_ALIGNMENT 8 70 #define MAX_ALIGNMENT DOUBLE_ALIGNMENT 73 #define PTR_ALIGN(addr, boundary) \ 74 ((char *)((((UINTPTR)(addr) + ((UINTPTR)((boundary)-1)))) \ 75 & ~((UINTPTR)((boundary)-1)))) 77 #define PTR_ALIGN(addr, boundary) \ 78 (memset((void*)(addr), 0,\ 79 DB_WASTED_ALIGN((UINTPTR)(addr), (UINTPTR)(boundary))),\ 80 (char *)((((UINTPTR)(addr) + ((UINTPTR)((boundary)-1)))) \ 81 & ~((UINTPTR)((boundary)-1)))) 84 #define DB_ALIGN(offset, align) \ 85 (((offset) + (align) - 1) & ~((align) - 1)) 87 #define DB_ALIGN_BELOW(offset, align) \ 88 ((offset) & ~((align) - 1)) 90 #define DB_WASTED_ALIGN(offset, align) \ 91 (DB_ALIGN((offset), (align)) - (offset)) 93 #define DB_ATT_ALIGN(offset) \ 94 (((offset) + (INT_ALIGNMENT) - 1) & ~((INT_ALIGNMENT) - 1)) 100 #define MEM_REGION_INIT_MARK '\0' 101 #define MEM_REGION_SCRAMBLE_MARK '\01' 102 #define MEM_REGION_GUARD_MARK '\02' 104 #if defined (CUBRID_DEBUG) 105 extern void db_scramble (
void *region,
int size);
106 #define MEM_REGION_INIT(region, size) \ 107 memset((region), MEM_REGION_SCRAMBLE_MARK, (size)) 108 #define MEM_REGION_SCRAMBLE(region, size) \ 109 memset (region, MEM_REGION_SCRAMBLE_MARK, size) 111 #define MEM_REGION_INIT(region, size) \ 112 memset((region), MEM_REGION_INIT_MARK, (size)) 113 #define MEM_REGION_SCRAMBLE(region, size) 117 #define db_private_free_and_init(thrd, ptr) \ 120 db_private_free ((thrd), (ptr)); \ 125 #define free_and_init(ptr) \ 128 free ((void*) (ptr)); \ 133 #define os_free_and_init(ptr) \ 141 #define db_private_free_and_init(thrd, ptr) \ 143 db_private_free ((thrd), (ptr)); \ 147 #define free_and_init(ptr) \ 149 free ((void*) (ptr)); \ 153 #define os_free_and_init(ptr) \ 163 #if !defined (SERVER_MODE) 167 #define os_malloc(size) (malloc (size)) 168 #define os_free(ptr) (free (ptr)) 169 #define os_realloc(ptr, size) (realloc ((ptr), (size))) 174 #define os_malloc(size) \ 175 os_malloc_debug(size, true, __FILE__, __LINE__) 176 extern void *os_malloc_debug (
size_t size,
bool rc_track,
const char *caller_file,
int caller_line);
177 #define os_calloc(n, size) \ 178 os_calloc_debug(n, size, true, __FILE__, __LINE__) 179 extern void *os_calloc_debug (
size_t n,
size_t size,
bool rc_track,
const char *caller_file,
int caller_line);
180 #define os_free(ptr) \ 181 os_free_debug(ptr, true, __FILE__, __LINE__) 182 extern void os_free_debug (
void *ptr,
bool rc_track,
const char *caller_file,
int caller_line);
183 #define os_realloc(ptr, size) (realloc ((ptr), (size))) 185 #define os_malloc(size) \ 186 os_malloc_release(size, false) 187 extern void *os_malloc_release (
size_t size,
bool rc_track);
188 #define os_calloc(n, size) \ 189 os_calloc_release(n, size, false) 190 extern void *os_calloc_release (
size_t n,
size_t size,
bool rc_track);
191 #define os_free(ptr) \ 192 os_free_release(ptr, false) 193 extern void os_free_release (
void *ptr,
bool rc_track);
194 #define os_realloc(ptr, size) (realloc ((ptr), (size))) 216 #if defined(ENABLE_UNUSED_FUNCTION) 217 extern void db_ostk_free (HL_HEAPID heap_id,
void *ptr);
227 #define db_private_alloc(thrd, size) \ 228 db_private_alloc_debug(thrd, size, true, __FILE__, __LINE__) 229 #define db_private_free(thrd, ptr) \ 230 db_private_free_debug(thrd, ptr, true, __FILE__, __LINE__) 231 #define db_private_realloc(thrd, ptr, size) \ 232 db_private_realloc_debug(thrd, ptr, size, true, __FILE__, __LINE__) 243 const char *caller_file,
int caller_line);
249 #define db_private_alloc(thrd, size) \ 250 db_private_alloc_release(thrd, size, false) 251 #define db_private_free(thrd, ptr) \ 252 db_private_free_release(thrd, ptr, false) 253 #define db_private_realloc(thrd, ptr, size) \ 254 db_private_realloc_release(thrd, ptr, size, false) 261 extern void *db_private_alloc_release (
THREAD_ENTRY * thrd,
size_t size,
bool rc_track);
262 extern void db_private_free_release (
THREAD_ENTRY * thrd,
void *ptr,
bool rc_track);
263 extern void *db_private_realloc_release (
THREAD_ENTRY * thrd,
void *ptr,
size_t size,
bool rc_track);
283 #if defined (SERVER_MODE) 284 extern HL_HEAPID db_private_set_heapid_to_thread (
THREAD_ENTRY * thread_p, HL_HEAPID heap_id);
285 #endif // SERVER_MODE 293 typedef struct private_malloc_header_s PRIVATE_MALLOC_HEADER;
294 struct private_malloc_header_s
300 #define PRIVATE_MALLOC_HEADER_MAGIC 0xafdaafdaU 304 PRIVATE_ALLOC_TYPE_LEA = 1,
305 PRIVATE_ALLOC_TYPE_WS = 2
308 #define PRIVATE_MALLOC_HEADER_ALIGNED_SIZE \ 309 ((sizeof(PRIVATE_MALLOC_HEADER) + 7) & ~7) 311 #define private_request_size(s) \ 312 (PRIVATE_MALLOC_HEADER_ALIGNED_SIZE + (s)) 314 #define private_hl2user_ptr(ptr) \ 315 (void *)((char *)(ptr) + PRIVATE_MALLOC_HEADER_ALIGNED_SIZE) 317 #define private_user2hl_ptr(ptr) \ 318 (PRIVATE_MALLOC_HEADER *)((char *)(ptr) - PRIVATE_MALLOC_HEADER_ALIGNED_SIZE) int db_align_to(int n, int alignment)
void * db_private_realloc_debug(THREAD_ENTRY *thrd, void *ptr, size_t size, bool rc_track, const char *caller_file, int caller_line)
HL_HEAPID db_replace_private_heap(THREAD_ENTRY *thread_p)
void * db_fixed_alloc(HL_HEAPID heap_id, size_t size)
void * db_private_alloc_external(THREAD_ENTRY *thrd, size_t size)
HL_HEAPID db_create_fixed_heap(int req_size, int recs_per_chunk)
HL_HEAPID db_change_private_heap(THREAD_ENTRY *thread_p, HL_HEAPID heap_id)
void * db_ostk_alloc(HL_HEAPID heap_id, size_t size)
void db_fixed_free(HL_HEAPID heap_id, void *ptr)
int ansisql_strcasecmp(const char *s, const char *t)
void db_destroy_fixed_heap(HL_HEAPID heap_id)
void db_destroy_private_heap(THREAD_ENTRY *thread_p, HL_HEAPID heap_id)
void db_clear_private_heap(THREAD_ENTRY *thread_p, HL_HEAPID heap_id)
HL_HEAPID db_create_ostk_heap(int chunk_size)
HL_HEAPID db_create_private_heap(void)
void db_destroy_ostk_heap(HL_HEAPID heap_id)
int ansisql_strcmp(const char *s, const char *t)
HL_HEAPID private_heap_id
void db_private_free_debug(THREAD_ENTRY *thrd, void *ptr, bool rc_track, const char *caller_file, int caller_line)
void * db_private_realloc_external(THREAD_ENTRY *thrd, void *ptr, size_t size)
char * db_private_strdup(THREAD_ENTRY *thrd, const char *s)
void db_private_free_external(THREAD_ENTRY *thrd, void *ptr)
void * db_private_alloc_debug(THREAD_ENTRY *thrd, size_t size, bool rc_track, const char *caller_file, int caller_line)