|
Go to the documentation of this file.
23 #ifndef __BMS_MEMORY_H__
24 #define __BMS_MEMORY_H__
32 template< typename T> T* docast(T*, void *v) { return reinterpret_cast<T* >(v); }
36 #define ASSIGN(pointerstarstar, voidstarfunction) (*(pointerstarstar) = docast(*(pointerstarstar), (voidstarfunction)))
40 #define ASSIGN(pointerstarstar, voidstarfunction) (*(pointerstarstar) = (voidstarfunction))
49 #if defined(_WIN32) || defined(_WIN64)
50 #define EXTERN __declspec(dllexport)
69 #define BMSallocMemoryArray(ptr,num) ASSIGN((ptr), BMSallocMemory_call( (num)*sizeof(**(ptr)), \
71 #define BMSreallocMemoryArray(ptr,num) ASSIGN((ptr), BMSreallocMemory_call( *(ptr), (num)*sizeof(**(ptr)), \
73 #define BMSallocMemoryArrayCPP(num,size) BMSallocMemory_call( (size_t)((num)*(size)), __FILE__, __LINE__ )
74 #define BMSallocClearMemoryArray(ptr,num) ASSIGN((ptr), BMSallocClearMemory_call((size_t)(num), sizeof(**(ptr)), __FILE__, __LINE__ ))
76 #define BMSallocMemoryArray(ptr,num) ( ( ((size_t)(num)) > (UINT_MAX / sizeof(**(ptr))) ) \
77 ? ( ASSIGN((ptr), NULL) ) \
78 : ( ASSIGN((ptr), BMSallocMemory_call( (num)*sizeof(**(ptr)), \
79 __FILE__, __LINE__ )) ) )
80 #define BMSreallocMemoryArray(ptr,num) ( ( ((size_t)(num)) > (UINT_MAX / sizeof(**(ptr))) ) \
81 ? ( ASSIGN((ptr), NULL) ) \
82 : ( ASSIGN((ptr), BMSreallocMemory_call( *(ptr), (num)*sizeof(**(ptr)), \
83 __FILE__, __LINE__ )) ) )
84 #define BMSallocMemoryArrayCPP(num,size) ( ( ((size_t)(num)) > (UINT_MAX / size) ) \
85 ? ( ASSIGN((ptr), NULL) ) \
86 :( BMSallocMemory_call( (size_t)((num)*(size)), __FILE__, __LINE__ ) ) )
87 #define BMSallocClearMemoryArray(ptr,num) ( ( ((size_t)(num)) > (UINT_MAX / sizeof(**(ptr))) ) \
88 ? ( ASSIGN((ptr), NULL) ) \
89 : ( ASSIGN((ptr), BMSallocClearMemory_call((size_t)(num), sizeof(**(ptr)), __FILE__, __LINE__ )) ) )
92 #define BMSallocMemory(ptr) ASSIGN((ptr), BMSallocMemory_call( sizeof(**(ptr)), __FILE__, __LINE__ ))
93 #define BMSallocMemorySize(ptr,size) ASSIGN((ptr), BMSallocMemory_call( (size_t)(size), __FILE__, __LINE__ ))
94 #define BMSallocMemoryCPP(size) BMSallocMemory_call( (size_t)(size), __FILE__, __LINE__ )
95 #define BMSreallocMemorySize(ptr,size) ASSIGN((ptr), BMSreallocMemory_call( *(ptr), (size_t)(size), \
97 #define BMSclearMemory(ptr) BMSclearMemory_call( (void*)(ptr), sizeof(*(ptr)) )
98 #define BMSclearMemoryArray(ptr, num) BMSclearMemory_call( (void*)(ptr), (num)*sizeof(*(ptr)) )
99 #define BMSclearMemorySize(ptr, size) BMSclearMemory_call( (void*)(ptr), (size_t)(size) )
101 #define BMScopyMemory(ptr, source) BMScopyMemory_call( (void*)(ptr), (const void*)(source), sizeof(*(ptr)) )
102 #define BMScopyMemoryArray(ptr, source, num) BMScopyMemory_call( (void*)(ptr), (const void*)(source), (num)*sizeof(*(ptr)) )
103 #define BMScopyMemorySize(ptr, source, size) BMScopyMemory_call( (void*)(ptr), (const void*)(source), (size_t)(size) )
105 #define BMSmoveMemory(ptr, source) BMSmoveMemory_call( (void*)(ptr), (const void*)(source), sizeof(*(ptr)) )
106 #define BMSmoveMemoryArray(ptr, source, num) BMSmoveMemory_call( (void*)(ptr), (const void*)(source), (num) * sizeof(*(ptr)) )
107 #define BMSmoveMemorySize(ptr, source, size) BMSmoveMemory_call( (void*)(ptr), (const void*)(source), (size_t)(size) )
109 #define BMSduplicateMemory(ptr, source) ASSIGN((ptr), BMSduplicateMemory_call( (const void*)(source), \
110 sizeof(**(ptr)), __FILE__, __LINE__ ))
111 #define BMSduplicateMemoryArray(ptr, source, num) \
112 ASSIGN((ptr), BMSduplicateMemory_call( (const void*)(source), \
113 (num)*sizeof(**(ptr)), __FILE__, __LINE__ ))
114 #define BMSduplicateMemorySize(ptr, source, size) \
115 ASSIGN((ptr), BMSduplicateMemory_call( (const void*)(source), \
116 (size_t)(size), __FILE__, __LINE__ ))
117 #define BMSfreeMemory(ptr) { BMSfreeMemory_call( (void*)(*(ptr)), __FILE__, __LINE__ ); \
119 #define BMSfreeMemoryNull(ptr) { if( *(ptr) != NULL ) BMSfreeMemory( (ptr) ); }
120 #define BMSfreeMemoryArray(ptr) { BMSfreeMemory_call( (void*)(*(ptr)), __FILE__, __LINE__ ); \
122 #define BMSfreeMemoryArrayNull(ptr) { if( *(ptr) != NULL ) BMSfreeMemoryArray( (ptr) ); }
123 #define BMSfreeMemorySize(ptr) { BMSfreeMemory_call( (void*)(*(ptr)), __FILE__, __LINE__ ); \
125 #define BMSfreeMemorySizeNull(ptr) { if( *(ptr) != NULL ) BMSfreeMemorySize( (ptr) ); }
128 #define BMSgetPointerSize(ptr) BMSgetPointerSize_call(ptr)
129 #define BMSdisplayMemory() BMSdisplayMemory_call()
130 #define BMScheckEmptyMemory() BMScheckEmptyMemory_call()
131 #define BMSgetMemoryUsed() BMSgetMemoryUsed_call()
133 #define BMSgetPointerSize(ptr) 0
134 #define BMSdisplayMemory()
135 #define BMScheckEmptyMemory()
136 #define BMSgetMemoryUsed() 0LL
144 const char* filename,
152 const char* filename,
161 const char* filename,
195 const char* filename,
203 const char* filename,
243 #ifndef BMS_NOBLOCKMEM
245 #define BMScreateChunkMemory(sz,isz,gbf) BMScreateChunkMemory_call( (sz), (isz), (gbf), __FILE__, __LINE__ )
246 #define BMSclearChunkMemory(mem) BMSclearChunkMemory_call( (mem), __FILE__, __LINE__ )
247 #define BMSclearChunkMemoryNull(mem) { if( (mem) != NULL ) BMSclearChunkMemory( (mem) ); }
248 #define BMSdestroyChunkMemory(mem) BMSdestroyChunkMemory_call( (mem), __FILE__, __LINE__ )
249 #define BMSdestroyChunkMemoryNull(mem) { if( *(mem) != NULL ) BMSdestroyChunkMemory( (mem) ); }
251 #define BMSallocChunkMemory(mem,ptr) ASSIGN((ptr), BMSallocChunkMemory_call((mem), sizeof(**(ptr)), \
253 #define BMSduplicateChunkMemory(mem, ptr, source) \
254 ASSIGN((ptr), BMSduplicateChunkMemory_call((mem), (const void*)(source), \
255 sizeof(**(ptr)), __FILE__, __LINE__ ))
256 #define BMSfreeChunkMemory(mem,ptr) { BMSfreeChunkMemory_call( (mem), (void*)(*(ptr)), sizeof(**(ptr)), \
257 __FILE__, __LINE__ ); \
259 #define BMSfreeChunkMemoryNull(mem,ptr) { if( *(ptr) != NULL ) BMSfreeChunkMemory( (mem), (ptr) ); }
260 #define BMSgarbagecollectChunkMemory(mem) BMSgarbagecollectChunkMemory_call(mem)
261 #define BMSgetChunkMemoryUsed(mem) BMSgetChunkMemoryUsed_call(mem)
267 #define BMScreateChunkMemory(sz,isz,gbf) (void*)(0x01)
268 #define BMSclearChunkMemory(mem)
269 #define BMSclearChunkMemoryNull(mem)
270 #define BMSdestroyChunkMemory(mem)
271 #define BMSdestroyChunkMemoryNull(mem)
272 #define BMSallocChunkMemory(mem,ptr) BMSallocMemory(ptr)
273 #define BMSduplicateChunkMemory(mem, ptr, source) BMSduplicateMemory(ptr,source)
274 #define BMSfreeChunkMemory(mem,ptr) BMSfreeMemory(ptr)
275 #define BMSfreeChunkMemoryNull(mem,ptr) BMSfreeMemoryNull(ptr)
276 #define BMSgarbagecollectChunkMemory(mem)
277 #define BMSgetChunkMemoryUsed(mem) 0LL
301 const char* filename,
309 const char* filename,
317 const char* filename,
326 const char* filename,
336 const char* filename,
346 const char* filename,
374 #ifndef BMS_NOBLOCKMEM
380 #define BMSallocBlockMemoryArray(mem,ptr,num) ASSIGN((ptr), BMSallocBlockMemory_call((mem), (num)*sizeof(**(ptr)), \
382 #define BMSreallocBlockMemoryArray(mem,ptr,oldnum,newnum) \
383 ASSIGN((ptr), BMSreallocBlockMemory_call((mem), (void*)(*(ptr)), \
384 (oldnum)*sizeof(**(ptr)), (newnum)*sizeof(**(ptr)), __FILE__, __LINE__))
386 #define BMSallocBlockMemoryArray(mem,ptr,num) ( ( ((size_t)(num)) > UINT_MAX / sizeof(**(ptr)) ) \
387 ? ( ASSIGN((ptr), NULL) ) \
388 : ( ASSIGN((ptr), BMSallocBlockMemory_call((mem), (num)*sizeof(**(ptr)),\
389 __FILE__, __LINE__)) ) )
390 #define BMSreallocBlockMemoryArray(mem,ptr,oldnum,newnum) \
391 ( ( ((size_t)(newnum)) > UINT_MAX / sizeof(**(ptr)) ) \
392 ? ( ASSIGN((ptr), NULL) ) \
393 : ( ASSIGN((ptr), BMSreallocBlockMemory_call((mem), (void*)(*(ptr)), \
394 (oldnum)*sizeof(**(ptr)), (newnum)*sizeof(**(ptr)), __FILE__, \
398 #define BMScreateBlockMemory(csz,gbf) BMScreateBlockMemory_call( (csz), (gbf), __FILE__, __LINE__ )
399 #define BMSclearBlockMemory(mem) BMSclearBlockMemory_call( (mem), __FILE__, __LINE__ )
400 #define BMSclearBlockMemoryNull(mem) { if( (mem) != NULL ) BMSclearBlockMemory( (mem) ); }
401 #define BMSdestroyBlockMemory(mem) BMSdestroyBlockMemory_call( (mem), __FILE__, __LINE__ )
402 #define BMSdestroyBlockMemoryNull(mem) { if( *(mem) != NULL ) BMSdestroyBlockMemory( (mem) ); }
404 #define BMSallocBlockMemory(mem,ptr) ASSIGN((ptr), BMSallocBlockMemory_call((mem), sizeof(**(ptr)), \
406 #define BMSallocBlockMemorySize(mem,ptr,size) ASSIGN((ptr), BMSallocBlockMemory_call((mem), (size_t)(size), \
408 #define BMSreallocBlockMemorySize(mem,ptr,oldsize,newsize) \
409 ASSIGN((ptr), BMSreallocBlockMemory_call((mem), (void*)(*(ptr)), \
410 (size_t)(oldsize), (size_t)(newsize), __FILE__, __LINE__))
411 #define BMSduplicateBlockMemory(mem, ptr, source) \
412 ASSIGN((ptr), BMSduplicateBlockMemory_call((mem), (const void*)(source), \
413 sizeof(**(ptr)), __FILE__, __LINE__ ))
414 #define BMSduplicateBlockMemoryArray(mem, ptr, source, num) \
415 ASSIGN((ptr), BMSduplicateBlockMemory_call( (mem), (const void*)(source), \
416 (num)*sizeof(**(ptr)), __FILE__, __LINE__ ))
417 #define BMSfreeBlockMemory(mem,ptr) { BMSfreeBlockMemory_call( (mem), (void*)(*(ptr)), sizeof(**(ptr)), \
418 __FILE__, __LINE__ ); \
420 #define BMSfreeBlockMemoryNull(mem,ptr) { if( *(ptr) != NULL ) BMSfreeBlockMemory( (mem), (ptr) ); }
421 #define BMSfreeBlockMemoryArray(mem,ptr,num) { BMSfreeBlockMemory_call( (mem), (void*)(*(ptr)), (num)*sizeof(**(ptr)), \
422 __FILE__, __LINE__ ); \
424 #define BMSfreeBlockMemoryArrayNull(mem,ptr,num) { if( *(ptr) != NULL ) BMSfreeBlockMemoryArray( (mem), (ptr), (num) ); }
425 #define BMSfreeBlockMemorySize(mem,ptr,size) { BMSfreeBlockMemory_call( (mem), (void*)(*(ptr)), (size_t)(size), \
426 __FILE__, __LINE__ ); \
428 #define BMSfreeBlockMemorySizeNull(mem,ptr,size) { if( *(ptr) != NULL ) BMSfreeBlockMemorySize( (mem), (ptr), (size) ); }
429 #define BMSgarbagecollectBlockMemory(mem) BMSgarbagecollectBlockMemory_call(mem)
430 #define BMSgetBlockMemoryUsed(mem) BMSgetBlockMemoryUsed_call(mem)
431 #define BMSgetBlockPointerSize(mem,ptr) BMSgetBlockPointerSize_call((mem), (ptr))
432 #define BMSdisplayBlockMemory(mem) BMSdisplayBlockMemory_call(mem)
433 #define BMSblockMemoryCheckEmpty(mem) BMScheckEmptyBlockMemory_call(mem)
439 #define BMScreateBlockMemory(csz,gbf) (void*)(0x01)
440 #define BMSclearBlockMemory(mem)
441 #define BMSclearBlockMemoryNull(mem)
442 #define BMSdestroyBlockMemory(mem)
443 #define BMSdestroyBlockMemoryNull(mem)
444 #define BMSallocBlockMemory(mem,ptr) BMSallocMemory(ptr)
445 #define BMSallocBlockMemoryArray(mem,ptr,num) BMSallocMemoryArray(ptr,num)
446 #define BMSallocBlockMemorySize(mem,ptr,size) BMSallocMemorySize(ptr,size)
447 #define BMSreallocBlockMemoryArray(mem,ptr,oldnum,newnum) BMSreallocMemoryArray(ptr,newnum)
448 #define BMSreallocBlockMemorySize(mem,ptr,oldsize,newsize) BMSreallocMemorySize(ptr,newsize)
449 #define BMSduplicateBlockMemory(mem, ptr, source) BMSduplicateMemory(ptr,source)
450 #define BMSduplicateBlockMemoryArray(mem, ptr, source, num) BMSduplicateMemoryArray(ptr,source,num)
451 #define BMSfreeBlockMemory(mem,ptr) BMSfreeMemory(ptr)
452 #define BMSfreeBlockMemoryNull(mem,ptr) BMSfreeMemoryNull(ptr)
453 #define BMSfreeBlockMemoryArray(mem,ptr,num) BMSfreeMemoryArray(ptr)
454 #define BMSfreeBlockMemoryArrayNull(mem,ptr,num) BMSfreeMemoryArrayNull(ptr)
455 #define BMSfreeBlockMemorySize(mem,ptr,size) BMSfreeMemory(ptr)
456 #define BMSfreeBlockMemorySizeNull(mem,ptr,size) BMSfreeMemoryNull(ptr)
457 #define BMSgarbagecollectBlockMemory(mem)
458 #define BMSgetBlockMemoryUsed(mem) 0LL
459 #define BMSgetBlockPointerSize(mem,ptr) 0
460 #define BMSdisplayBlockMemory(mem)
461 #define BMSblockMemoryCheckEmpty(mem)
472 const char* filename,
480 const char* filename,
488 const char* filename,
496 const char* filename,
507 const char* filename,
517 const char* filename,
527 const char* filename,
|