Changeset 709b812 for libcfa/src
- Timestamp:
- Jan 10, 2021, 11:46:29 AM (4 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- e112a24
- Parents:
- 0783909
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/heap.cfa
r0783909 r709b812 10 10 // Created On : Tue Dec 19 21:58:35 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Dec 16 12:28:25 202013 // Update Count : 10 2312 // Last Modified On : Sun Jan 10 11:20:49 2021 13 // Update Count : 1031 14 14 // 15 15 … … 262 262 #ifdef __STATISTICS__ 263 263 // Heap statistics counters. 264 static unsigned int malloc_ calls;264 static unsigned int malloc_zero_calls, malloc_calls; 265 265 static unsigned long long int malloc_storage; 266 static unsigned int aalloc_ calls;266 static unsigned int aalloc_zero_calls, aalloc_calls; 267 267 static unsigned long long int aalloc_storage; 268 static unsigned int calloc_ calls;268 static unsigned int calloc_zero_calls, calloc_calls; 269 269 static unsigned long long int calloc_storage; 270 static unsigned int memalign_ calls;270 static unsigned int memalign_zero_calls, memalign_calls; 271 271 static unsigned long long int memalign_storage; 272 static unsigned int amemalign_ calls;272 static unsigned int amemalign_zero_calls, amemalign_calls; 273 273 static unsigned long long int amemalign_storage; 274 static unsigned int cmemalign_ calls;274 static unsigned int cmemalign_zero_calls, cmemalign_calls; 275 275 static unsigned long long int cmemalign_storage; 276 static unsigned int resize_ calls;276 static unsigned int resize_zero_calls, resize_calls; 277 277 static unsigned long long int resize_storage; 278 static unsigned int realloc_ calls;278 static unsigned int realloc_zero_calls, realloc_calls; 279 279 static unsigned long long int realloc_storage; 280 static unsigned int free_ calls;280 static unsigned int free_zero_calls, free_calls; 281 281 static unsigned long long int free_storage; 282 282 static unsigned int mmap_calls; … … 287 287 static unsigned long long int sbrk_storage; 288 288 // Statistics file descriptor (changed by malloc_stats_fd). 289 static int stat _fd = STDERR_FILENO;// default stderr289 static int stats_fd = STDERR_FILENO; // default stderr 290 290 291 291 // Use "write" because streams may be shutdown when calls are made. … … 293 293 char helpText[1024]; 294 294 __cfaabi_bits_print_buffer( STDERR_FILENO, helpText, sizeof(helpText), 295 296 " malloc: calls %u / storage %llu\n"297 " aalloc: calls %u / storage %llu\n"298 " calloc: calls %u / storage %llu\n"299 " memalign: calls %u / storage %llu\n"300 " amemalign: calls %u / storage %llu\n"301 " cmemalign: calls %u / storage %llu\n"302 " resize: calls %u / storage %llu\n"303 " realloc: calls %u / storage %llu\n"304 " free: calls %u / storage %llu\n"305 " mmap: calls %u / storage %llu\n"306 " munmap: calls %u / storage %llu\n"307 " sbrk: calls %u / storage %llu\n",308 309 310 311 312 313 314 315 316 317 318 319 295 "\nHeap statistics:\n" 296 " malloc 0-calls %'u; >0-calls %'u; storage %'llu bytes\n" 297 " aalloc 0-calls %'u; >0-calls %'u; storage %'llu bytes\n" 298 " calloc 0-calls %'u; >0-calls %'u; storage %'llu bytes\n" 299 " memalign 0-calls %'u; >0-calls %'u; storage %'llu bytes\n" 300 " amemalign 0-calls %'u; >0-calls %'u; storage %'llu bytes\n" 301 " cmemalign 0-calls %'u; >0-calls %'u; storage %'llu bytes\n" 302 " resize 0-calls %'u; >0-calls %'u; storage %'llu bytes\n" 303 " realloc 0-calls %'u; >0-calls %'u; storage %'llu bytes\n" 304 " free 0-calls %'u; >0-calls %'u; storage %'llu bytes\n" 305 " mmap calls %'u; storage %'llu bytes\n" 306 " munmap calls %'u; storage %'llu bytes\n" 307 " sbrk calls %'u; storage %'llu bytes\n", 308 malloc_zero_calls, malloc_calls, malloc_storage, 309 aalloc_zero_calls, aalloc_calls, aalloc_storage, 310 calloc_zero_calls, calloc_calls, calloc_storage, 311 memalign_zero_calls, memalign_calls, memalign_storage, 312 amemalign_zero_calls, amemalign_calls, amemalign_storage, 313 cmemalign_zero_calls, cmemalign_calls, cmemalign_storage, 314 resize_zero_calls, resize_calls, resize_storage, 315 realloc_zero_calls, realloc_calls, realloc_storage, 316 free_zero_calls, free_calls, free_storage, 317 mmap_calls, mmap_storage, 318 munmap_calls, munmap_storage, 319 sbrk_calls, sbrk_storage 320 320 ); 321 321 } // printStats … … 328 328 "<sizes>\n" 329 329 "</sizes>\n" 330 "<total type=\"malloc\" count=\"%u\" size=\"%llu\"/>\n"331 "<total type=\"aalloc\" count=\"%u\" size=\"%llu\"/>\n"332 "<total type=\"calloc\" count=\"%u\" size=\"%llu\"/>\n"333 "<total type=\"memalign\" count=\"%u\" size=\"%llu\"/>\n"334 "<total type=\"amemalign\" count=\"%u\" size=\"%llu\"/>\n"335 "<total type=\"cmemalign\" count=\"%u\" size=\"%llu\"/>\n"336 "<total type=\"resize\" count=\"%u\" size=\"%llu\"/>\n"337 "<total type=\"realloc\" count=\"%u\" size=\"%llu\"/>\n"338 "<total type=\"free\" count=\"%u\" size=\"%llu\"/>\n"339 "<total type=\"mmap\" count=\"% u\" size=\"%llu\"/>\n"340 "<total type=\"munmap\" count=\"% u\" size=\"%llu\"/>\n"341 "<total type=\"sbrk\" count=\"% u\" size=\"%llu\"/>\n"330 "<total type=\"malloc\" 0 count=\"%'u;\" >0 count=\"%'u;\" size=\"%'llu\"/> bytes\n" 331 "<total type=\"aalloc\" 0 count=\"%'u;\" >0 count=\"%'u;\" size=\"%'llu\"/> bytes\n" 332 "<total type=\"calloc\" 0 count=\"%'u;\" >0 count=\"%'u;\" size=\"%'llu\"/> bytes\n" 333 "<total type=\"memalign\" 0 count=\"%'u;\" >0 count=\"%'u;\" size=\"%'llu\"/> bytes\n" 334 "<total type=\"amemalign\" 0 count=\"%'u;\" >0 count=\"%'u;\" size=\"%'llu\"/> bytes\n" 335 "<total type=\"cmemalign\" 0 count=\"%'u;\" >0 count=\"%'u;\" size=\"%'llu\"/> bytes\n" 336 "<total type=\"resize\" 0 count=\"%'u;\" >0 count=\"%'u;\" size=\"%'llu\"/> bytes\n" 337 "<total type=\"realloc\" 0 count=\"%'u;\" >0 count=\"%'u;\" size=\"%'llu\"/> bytes\n" 338 "<total type=\"free\" 0 count=\"%'u;\" >0 count=\"%'u;\" size=\"%'llu\"/> bytes\n" 339 "<total type=\"mmap\" count=\"%'u;\" size=\"%'llu\"/> bytes\n" 340 "<total type=\"munmap\" count=\"%'u;\" size=\"%'llu\"/> bytes\n" 341 "<total type=\"sbrk\" count=\"%'u;\" size=\"%'llu\"/> bytes\n" 342 342 "</malloc>", 343 malloc_ calls, malloc_storage,344 aalloc_ calls, aalloc_storage,345 calloc_ calls, calloc_storage,346 memalign_ calls, memalign_storage,347 amemalign_ calls, amemalign_storage,348 cmemalign_ calls, cmemalign_storage,349 resize_ calls, resize_storage,350 realloc_ calls, realloc_storage,351 free_ calls, free_storage,343 malloc_zero_calls, malloc_calls, malloc_storage, 344 aalloc_zero_calls, aalloc_calls, aalloc_storage, 345 calloc_zero_calls, calloc_calls, calloc_storage, 346 memalign_zero_calls, memalign_calls, memalign_storage, 347 amemalign_zero_calls, amemalign_calls, amemalign_storage, 348 cmemalign_zero_calls, cmemalign_calls, cmemalign_storage, 349 resize_zero_calls, resize_calls, resize_storage, 350 realloc_zero_calls, realloc_calls, realloc_storage, 351 free_zero_calls, free_calls, free_storage, 352 352 mmap_calls, mmap_storage, 353 353 munmap_calls, munmap_storage, … … 466 466 } // headers 467 467 468 #ifdef __CFA_DEBUG__469 #if __SIZEOF_POINTER__ == 4470 #define MASK 0xdeadbeef471 #else472 #define MASK 0xdeadbeefdeadbeef473 #endif474 #define STRIDE size_t475 476 static void * Memset( void * addr, STRIDE size ) { // debug only477 if ( size % sizeof(STRIDE) != 0 ) abort( "Memset() : internal error, size %zd not multiple of %zd.", size, sizeof(STRIDE) );478 if ( (STRIDE)addr % sizeof(STRIDE) != 0 ) abort( "Memset() : internal error, addr %p not multiple of %zd.", addr, sizeof(STRIDE) );479 480 STRIDE * end = (STRIDE *)addr + size / sizeof(STRIDE);481 for ( STRIDE * p = (STRIDE *)addr; p < end; p += 1 ) *p = MASK;482 return addr;483 } // Memset484 #endif // __CFA_DEBUG__468 // #ifdef __CFA_DEBUG__ 469 // #if __SIZEOF_POINTER__ == 4 470 // #define MASK 0xdeadbeef 471 // #else 472 // #define MASK 0xdeadbeefdeadbeef 473 // #endif 474 // #define STRIDE size_t 475 476 // static void * Memset( void * addr, STRIDE size ) { // debug only 477 // if ( size % sizeof(STRIDE) != 0 ) abort( "Memset() : internal error, size %zd not multiple of %zd.", size, sizeof(STRIDE) ); 478 // if ( (STRIDE)addr % sizeof(STRIDE) != 0 ) abort( "Memset() : internal error, addr %p not multiple of %zd.", addr, sizeof(STRIDE) ); 479 480 // STRIDE * end = (STRIDE *)addr + size / sizeof(STRIDE); 481 // for ( STRIDE * p = (STRIDE *)addr; p < end; p += 1 ) *p = MASK; 482 // return addr; 483 // } // Memset 484 // #endif // __CFA_DEBUG__ 485 485 486 486 … … 498 498 unlock( extlock ); 499 499 __cfaabi_bits_print_nolock( STDERR_FILENO, NO_MEMORY_MSG, size ); 500 _exit( EXIT_FAILURE ); 501 } // if 500 _exit( EXIT_FAILURE ); // give up 501 } // if 502 // Make storage executable for thunks. 502 503 if ( mprotect( (char *)heapEnd + heapRemaining, increase, __map_prot ) ) { 503 504 unlock( extlock ); … … 770 771 771 772 772 static inline void * callocNoStats( size_t dim, size_t elemSize ) {773 size_t size = dim * elemSize;774 if ( unlikely( size ) == 0 ) return 0p; // 0 BYTE ALLOCATION RETURNS NULL POINTER775 char * addr = (char *)mallocNoStats( size );776 777 HeapManager.Storage.Header * header;778 HeapManager.FreeHeader * freeElem;779 size_t bsize, alignment;780 #ifndef __CFA_DEBUG__781 bool mapped =782 #endif // __CFA_DEBUG__783 headers( "calloc", addr, header, freeElem, bsize, alignment );784 #ifndef __CFA_DEBUG__785 786 // Mapped storage is zero filled, but in debug mode mapped memory is scrubbed in doMalloc, so it has to be reset to zero.787 if ( ! mapped )788 #endif // __CFA_DEBUG__789 // <-------0000000000000000000000000000UUUUUUUUUUUUUUUUUUUUUUUUU> bsize (bucket size) U => undefined790 // `-header`-addr `-size791 memset( addr, '\0', size ); // set to zeros792 793 header->kind.real.blockSize |= 2; // mark as zero filled794 return addr;795 } // callocNoStats796 797 798 773 static inline void * memalignNoStats( size_t alignment, size_t size ) { 799 774 if ( unlikely( size ) == 0 ) return 0p; // 0 BYTE ALLOCATION RETURNS NULL POINTER … … 834 809 835 810 836 static inline void * cmemalignNoStats( size_t alignment, size_t dim, size_t elemSize ) {837 size_t size = dim * elemSize;838 if ( unlikely( size ) == 0 ) return 0p; // 0 BYTE ALLOCATION RETURNS NULL POINTER839 char * addr = (char *)memalignNoStats( alignment, size );840 841 HeapManager.Storage.Header * header;842 HeapManager.FreeHeader * freeElem;843 size_t bsize;844 #ifndef __CFA_DEBUG__845 bool mapped =846 #endif // __CFA_DEBUG__847 headers( "cmemalign", addr, header, freeElem, bsize, alignment );848 849 // Mapped storage is zero filled, but in debug mode mapped memory is scrubbed in doMalloc, so it has to be reset to zero.850 #ifndef __CFA_DEBUG__851 if ( ! mapped )852 #endif // __CFA_DEBUG__853 // <-------0000000000000000000000000000UUUUUUUUUUUUUUUUUUUUUUUUU> bsize (bucket size) U => undefined854 // `-header`-addr `-size855 memset( addr, '\0', size ); // set to zeros856 857 header->kind.real.blockSize |= 2; // mark as zero filled858 return addr;859 } // cmemalignNoStats860 861 862 811 extern "C" { 863 812 // Allocates size bytes and returns a pointer to the allocated memory. The contents are undefined. If size is 0, … … 865 814 void * malloc( size_t size ) { 866 815 #ifdef __STATISTICS__ 867 __atomic_add_fetch( &malloc_calls, 1, __ATOMIC_SEQ_CST ); 868 __atomic_add_fetch( &malloc_storage, size, __ATOMIC_SEQ_CST ); 816 if ( likely( size > 0 ) ) { 817 __atomic_add_fetch( &malloc_calls, 1, __ATOMIC_SEQ_CST ); 818 __atomic_add_fetch( &malloc_storage, size, __ATOMIC_SEQ_CST ); 819 } else { 820 __atomic_add_fetch( &malloc_zero_calls, 1, __ATOMIC_SEQ_CST ); 821 } // if 869 822 #endif // __STATISTICS__ 870 823 … … 877 830 size_t size = dim * elemSize; 878 831 #ifdef __STATISTICS__ 879 __atomic_add_fetch( &aalloc_calls, 1, __ATOMIC_SEQ_CST ); 880 __atomic_add_fetch( &aalloc_storage, size, __ATOMIC_SEQ_CST ); 832 if ( likely( size > 0 ) ) { 833 __atomic_add_fetch( &aalloc_calls, 1, __ATOMIC_SEQ_CST ); 834 __atomic_add_fetch( &aalloc_storage, size, __ATOMIC_SEQ_CST ); 835 } else { 836 __atomic_add_fetch( &aalloc_zero_calls, 1, __ATOMIC_SEQ_CST ); 837 } // if 881 838 #endif // __STATISTICS__ 882 839 … … 887 844 // Same as aalloc() with memory set to zero. 888 845 void * calloc( size_t dim, size_t elemSize ) { 846 size_t size = dim * elemSize; 847 if ( unlikely( size ) == 0 ) { // 0 BYTE ALLOCATION RETURNS NULL POINTER 848 #ifdef __STATISTICS__ 849 __atomic_add_fetch( &calloc_zero_calls, 1, __ATOMIC_SEQ_CST ); 850 #endif // __STATISTICS__ 851 return 0p; 852 } // if 889 853 #ifdef __STATISTICS__ 890 854 __atomic_add_fetch( &calloc_calls, 1, __ATOMIC_SEQ_CST ); … … 892 856 #endif // __STATISTICS__ 893 857 894 return callocNoStats( dim, elemSize ); 858 char * addr = (char *)mallocNoStats( size ); 859 860 HeapManager.Storage.Header * header; 861 HeapManager.FreeHeader * freeElem; 862 size_t bsize, alignment; 863 864 #ifndef __CFA_DEBUG__ 865 bool mapped = 866 #endif // __CFA_DEBUG__ 867 headers( "calloc", addr, header, freeElem, bsize, alignment ); 868 869 #ifndef __CFA_DEBUG__ 870 // Mapped storage is zero filled, but in debug mode mapped memory is scrubbed in doMalloc, so it has to be reset to zero. 871 if ( ! mapped ) 872 #endif // __CFA_DEBUG__ 873 // <-------0000000000000000000000000000UUUUUUUUUUUUUUUUUUUUUUUUU> bsize (bucket size) U => undefined 874 // `-header`-addr `-size 875 memset( addr, '\0', size ); // set to zeros 876 877 header->kind.real.blockSize |= 2; // mark as zero filled 878 return addr; 895 879 } // calloc 896 880 … … 901 885 // call to malloc(), alloc(), calloc() or realloc(). If the area pointed to was moved, a free(oaddr) is done. 902 886 void * resize( void * oaddr, size_t size ) { 887 // If size is equal to 0, either NULL or a pointer suitable to be passed to free() is returned. 888 if ( unlikely( size == 0 ) ) { // special cases 889 #ifdef __STATISTICS__ 890 __atomic_add_fetch( &resize_zero_calls, 1, __ATOMIC_SEQ_CST ); 891 #endif // __STATISTICS__ 892 free( oaddr ); 893 return 0p; 894 } // if 903 895 #ifdef __STATISTICS__ 904 896 __atomic_add_fetch( &resize_calls, 1, __ATOMIC_SEQ_CST ); 905 897 #endif // __STATISTICS__ 906 898 907 // If size is equal to 0, either NULL or a pointer suitable to be passed to free() is returned.908 if ( unlikely( size == 0 ) ) { free( oaddr ); return 0p; } // special cases909 899 if ( unlikely( oaddr == 0p ) ) { 910 900 #ifdef __STATISTICS__ … … 918 908 size_t bsize, oalign; 919 909 headers( "resize", oaddr, header, freeElem, bsize, oalign ); 910 920 911 size_t odsize = dataStorage( bsize, oaddr, header ); // data storage available in bucket 921 922 912 // same size, DO NOT preserve STICKY PROPERTIES. 923 913 if ( oalign == libAlign() && size <= odsize && odsize <= size * 2 ) { // allow 50% wasted storage for smaller size … … 940 930 // the old and new sizes. 941 931 void * realloc( void * oaddr, size_t size ) { 932 // If size is equal to 0, either NULL or a pointer suitable to be passed to free() is returned. 933 if ( unlikely( size == 0 ) ) { // special cases 934 #ifdef __STATISTICS__ 935 __atomic_add_fetch( &realloc_zero_calls, 1, __ATOMIC_SEQ_CST ); 936 #endif // __STATISTICS__ 937 free( oaddr ); 938 return 0p; 939 } // if 942 940 #ifdef __STATISTICS__ 943 941 __atomic_add_fetch( &realloc_calls, 1, __ATOMIC_SEQ_CST ); 944 942 #endif // __STATISTICS__ 945 943 946 // If size is equal to 0, either NULL or a pointer suitable to be passed to free() is returned.947 if ( unlikely( size == 0 ) ) { free( oaddr ); return 0p; } // special cases948 944 if ( unlikely( oaddr == 0p ) ) { 949 945 #ifdef __STATISTICS__ … … 999 995 void * memalign( size_t alignment, size_t size ) { 1000 996 #ifdef __STATISTICS__ 1001 __atomic_add_fetch( &memalign_calls, 1, __ATOMIC_SEQ_CST ); 1002 __atomic_add_fetch( &memalign_storage, size, __ATOMIC_SEQ_CST ); 997 if ( likely( size > 0 ) ) { 998 __atomic_add_fetch( &memalign_calls, 1, __ATOMIC_SEQ_CST ); 999 __atomic_add_fetch( &memalign_storage, size, __ATOMIC_SEQ_CST ); 1000 } else { 1001 __atomic_add_fetch( &memalign_zero_calls, 1, __ATOMIC_SEQ_CST ); 1002 } // if 1003 1003 #endif // __STATISTICS__ 1004 1004 … … 1011 1011 size_t size = dim * elemSize; 1012 1012 #ifdef __STATISTICS__ 1013 __atomic_add_fetch( &cmemalign_calls, 1, __ATOMIC_SEQ_CST ); 1014 __atomic_add_fetch( &cmemalign_storage, size, __ATOMIC_SEQ_CST ); 1013 if ( likely( size > 0 ) ) { 1014 __atomic_add_fetch( &cmemalign_calls, 1, __ATOMIC_SEQ_CST ); 1015 __atomic_add_fetch( &cmemalign_storage, size, __ATOMIC_SEQ_CST ); 1016 } else { 1017 __atomic_add_fetch( &cmemalign_zero_calls, 1, __ATOMIC_SEQ_CST ); 1018 } // if 1015 1019 #endif // __STATISTICS__ 1016 1020 … … 1021 1025 // Same as calloc() with memory alignment. 1022 1026 void * cmemalign( size_t alignment, size_t dim, size_t elemSize ) { 1027 size_t size = dim * elemSize; 1028 if ( unlikely( size ) == 0 ) { // 0 BYTE ALLOCATION RETURNS NULL POINTER 1029 #ifdef __STATISTICS__ 1030 __atomic_add_fetch( &cmemalign_zero_calls, 1, __ATOMIC_SEQ_CST ); 1031 #endif // __STATISTICS__ 1032 return 0p; 1033 } // if 1023 1034 #ifdef __STATISTICS__ 1024 1035 __atomic_add_fetch( &cmemalign_calls, 1, __ATOMIC_SEQ_CST ); … … 1026 1037 #endif // __STATISTICS__ 1027 1038 1028 return cmemalignNoStats( alignment, dim, elemSize ); 1039 char * addr = (char *)memalignNoStats( alignment, size ); 1040 1041 HeapManager.Storage.Header * header; 1042 HeapManager.FreeHeader * freeElem; 1043 size_t bsize; 1044 1045 #ifndef __CFA_DEBUG__ 1046 bool mapped = 1047 #endif // __CFA_DEBUG__ 1048 headers( "cmemalign", addr, header, freeElem, bsize, alignment ); 1049 1050 // Mapped storage is zero filled, but in debug mode mapped memory is scrubbed in doMalloc, so it has to be reset to zero. 1051 #ifndef __CFA_DEBUG__ 1052 if ( ! mapped ) 1053 #endif // __CFA_DEBUG__ 1054 // <-------0000000000000000000000000000UUUUUUUUUUUUUUUUUUUUUUUUU> bsize (bucket size) U => undefined 1055 // `-header`-addr `-size 1056 memset( addr, '\0', size ); // set to zeros 1057 1058 header->kind.real.blockSize |= 2; // mark as zero filled 1059 return addr; 1029 1060 } // cmemalign 1030 1061 … … 1065 1096 // 0p, no operation is performed. 1066 1097 void free( void * addr ) { 1067 #ifdef __STATISTICS__1068 __atomic_add_fetch( &free_calls, 1, __ATOMIC_SEQ_CST );1069 #endif // __STATISTICS__1070 1071 1098 if ( unlikely( addr == 0p ) ) { // special case 1099 #ifdef __STATISTICS__ 1100 __atomic_add_fetch( &free_zero_calls, 1, __ATOMIC_SEQ_CST ); 1101 #endif // __STATISTICS__ 1102 1072 1103 // #ifdef __CFA_DEBUG__ 1073 1104 // if ( traceHeap() ) { … … 1182 1213 int malloc_stats_fd( int fd __attribute__(( unused )) ) { 1183 1214 #ifdef __STATISTICS__ 1184 int temp = stat _fd;1185 stat _fd = fd;1215 int temp = stats_fd; 1216 stats_fd = fd; 1186 1217 return temp; 1187 1218 #else … … 1214 1245 // The string is printed on the file stream stream. The exported string includes information about all arenas (see 1215 1246 // malloc). 1216 int malloc_info( int options, FILE * stream ) {1247 int malloc_info( int options, FILE * stream __attribute__(( unused )) ) { 1217 1248 if ( options != 0 ) { errno = EINVAL; return -1; } 1218 1249 #ifdef __STATISTICS__ … … 1243 1274 // Must have CFA linkage to overload with C linkage realloc. 1244 1275 void * resize( void * oaddr, size_t nalign, size_t size ) { 1245 #ifdef __STATISTICS__ 1246 __atomic_add_fetch( &resize_calls, 1, __ATOMIC_SEQ_CST ); 1247 #endif // __STATISTICS__ 1276 // If size is equal to 0, either NULL or a pointer suitable to be passed to free() is returned. 1277 if ( unlikely( size == 0 ) ) { // special cases 1278 #ifdef __STATISTICS__ 1279 __atomic_add_fetch( &resize_zero_calls, 1, __ATOMIC_SEQ_CST ); 1280 #endif // __STATISTICS__ 1281 free( oaddr ); 1282 return 0p; 1283 } // if 1248 1284 1249 1285 if ( unlikely( nalign < libAlign() ) ) nalign = libAlign(); // reset alignment to minimum 1250 1286 #ifdef __CFA_DEBUG__ 1251 else 1252 checkAlign( nalign ); // check alignment 1287 else checkAlign( nalign ); // check alignment 1253 1288 #endif // __CFA_DEBUG__ 1254 1289 1255 // If size is equal to 0, either NULL or a pointer suitable to be passed to free() is returned.1256 if ( unlikely( size == 0 ) ) { free( oaddr ); return 0p; } // special cases1257 1290 if ( unlikely( oaddr == 0p ) ) { 1258 1291 #ifdef __STATISTICS__ 1292 __atomic_add_fetch( &resize_calls, 1, __ATOMIC_SEQ_CST ); 1259 1293 __atomic_add_fetch( &resize_storage, size, __ATOMIC_SEQ_CST ); 1260 1294 #endif // __STATISTICS__ … … 1302 1336 1303 1337 void * realloc( void * oaddr, size_t nalign, size_t size ) { 1338 // If size is equal to 0, either NULL or a pointer suitable to be passed to free() is returned. 1339 if ( unlikely( size == 0 ) ) { // special cases 1340 #ifdef __STATISTICS__ 1341 __atomic_add_fetch( &realloc_zero_calls, 1, __ATOMIC_SEQ_CST ); 1342 #endif // __STATISTICS__ 1343 free( oaddr ); 1344 return 0p; 1345 } // if 1346 1304 1347 if ( unlikely( nalign < libAlign() ) ) nalign = libAlign(); // reset alignment to minimum 1305 1348 #ifdef __CFA_DEBUG__ 1306 else 1307 checkAlign( nalign ); // check alignment 1349 else checkAlign( nalign ); // check alignment 1308 1350 #endif // __CFA_DEBUG__ 1309 1351 1310 // If size is equal to 0, either NULL or a pointer suitable to be passed to free() is returned.1311 if ( unlikely( size == 0 ) ) { free( oaddr ); return 0p; } // special cases1312 1352 if ( unlikely( oaddr == 0p ) ) { 1313 1353 #ifdef __STATISTICS__
Note: See TracChangeset
for help on using the changeset viewer.