Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/heap.cfa

    r709b812 r13fece5  
    1010// Created On       : Tue Dec 19 21:58:35 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Jan 10 11:20:49 2021
    13 // Update Count     : 1031
     12// Last Modified On : Wed Dec 16 12:28:25 2020
     13// Update Count     : 1023
    1414//
    1515
     
    262262#ifdef __STATISTICS__
    263263// Heap statistics counters.
    264 static unsigned int malloc_zero_calls, malloc_calls;
     264static unsigned int malloc_calls;
    265265static unsigned long long int malloc_storage;
    266 static unsigned int aalloc_zero_calls, aalloc_calls;
     266static unsigned int aalloc_calls;
    267267static unsigned long long int aalloc_storage;
    268 static unsigned int calloc_zero_calls, calloc_calls;
     268static unsigned int calloc_calls;
    269269static unsigned long long int calloc_storage;
    270 static unsigned int memalign_zero_calls, memalign_calls;
     270static unsigned int memalign_calls;
    271271static unsigned long long int memalign_storage;
    272 static unsigned int amemalign_zero_calls, amemalign_calls;
     272static unsigned int amemalign_calls;
    273273static unsigned long long int amemalign_storage;
    274 static unsigned int cmemalign_zero_calls, cmemalign_calls;
     274static unsigned int cmemalign_calls;
    275275static unsigned long long int cmemalign_storage;
    276 static unsigned int resize_zero_calls, resize_calls;
     276static unsigned int resize_calls;
    277277static unsigned long long int resize_storage;
    278 static unsigned int realloc_zero_calls, realloc_calls;
     278static unsigned int realloc_calls;
    279279static unsigned long long int realloc_storage;
    280 static unsigned int free_zero_calls, free_calls;
     280static unsigned int free_calls;
    281281static unsigned long long int free_storage;
    282282static unsigned int mmap_calls;
     
    287287static unsigned long long int sbrk_storage;
    288288// Statistics file descriptor (changed by malloc_stats_fd).
    289 static int stats_fd = STDERR_FILENO;                                    // default stderr
     289static int stat_fd = STDERR_FILENO;                                             // default stderr
    290290
    291291// Use "write" because streams may be shutdown when calls are made.
     
    293293        char helpText[1024];
    294294        __cfaabi_bits_print_buffer( STDERR_FILENO, helpText, sizeof(helpText),
    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
     295                                                                        "\nHeap statistics:\n"
     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                                                                        malloc_calls, malloc_storage,
     309                                                                        aalloc_calls, aalloc_storage,
     310                                                                        calloc_calls, calloc_storage,
     311                                                                        memalign_calls, memalign_storage,
     312                                                                        amemalign_calls, amemalign_storage,
     313                                                                        cmemalign_calls, cmemalign_storage,
     314                                                                        resize_calls, resize_storage,
     315                                                                        realloc_calls, realloc_storage,
     316                                                                        free_calls, free_storage,
     317                                                                        mmap_calls, mmap_storage,
     318                                                                        munmap_calls, munmap_storage,
     319                                                                        sbrk_calls, sbrk_storage
    320320                );
    321321} // printStats
     
    328328                                                "<sizes>\n"
    329329                                                "</sizes>\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"
     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"
    342342                                                "</malloc>",
    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,
     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,
    352352                                                mmap_calls, mmap_storage,
    353353                                                munmap_calls, munmap_storage,
     
    466466} // headers
    467467
    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__
     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
     476static 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__
    485485
    486486
     
    498498                        unlock( extlock );
    499499                        __cfaabi_bits_print_nolock( STDERR_FILENO, NO_MEMORY_MSG, size );
    500                         _exit( EXIT_FAILURE );                                          // give up
    501                 } // if
    502                 // Make storage executable for thunks.
     500                        _exit( EXIT_FAILURE );
     501                } // if
    503502                if ( mprotect( (char *)heapEnd + heapRemaining, increase, __map_prot ) ) {
    504503                        unlock( extlock );
     
    771770
    772771
     772static 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 POINTER
     775        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 => undefined
     790                // `-header`-addr                      `-size
     791                memset( addr, '\0', size );                                             // set to zeros
     792
     793        header->kind.real.blockSize |= 2;                                       // mark as zero filled
     794        return addr;
     795} // callocNoStats
     796
     797
    773798static inline void * memalignNoStats( size_t alignment, size_t size ) {
    774799  if ( unlikely( size ) == 0 ) return 0p;                               // 0 BYTE ALLOCATION RETURNS NULL POINTER
     
    809834
    810835
     836static 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 POINTER
     839        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 => undefined
     854                // `-header`-addr                      `-size
     855                memset( addr, '\0', size );                                             // set to zeros
     856
     857        header->kind.real.blockSize |= 2;                                       // mark as zero filled
     858        return addr;
     859} // cmemalignNoStats
     860
     861
    811862extern "C" {
    812863        // Allocates size bytes and returns a pointer to the allocated memory.  The contents are undefined. If size is 0,
     
    814865        void * malloc( size_t size ) {
    815866                #ifdef __STATISTICS__
    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
     867                __atomic_add_fetch( &malloc_calls, 1, __ATOMIC_SEQ_CST );
     868                __atomic_add_fetch( &malloc_storage, size, __ATOMIC_SEQ_CST );
    822869                #endif // __STATISTICS__
    823870
     
    830877                size_t size = dim * elemSize;
    831878                #ifdef __STATISTICS__
    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
     879                __atomic_add_fetch( &aalloc_calls, 1, __ATOMIC_SEQ_CST );
     880                __atomic_add_fetch( &aalloc_storage, size, __ATOMIC_SEQ_CST );
    838881                #endif // __STATISTICS__
    839882
     
    844887        // Same as aalloc() with memory set to zero.
    845888        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
    853889                #ifdef __STATISTICS__
    854890                __atomic_add_fetch( &calloc_calls, 1, __ATOMIC_SEQ_CST );
     
    856892                #endif // __STATISTICS__
    857893
    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;
     894                return callocNoStats( dim, elemSize );
    879895        } // calloc
    880896
     
    885901        // call to malloc(), alloc(), calloc() or realloc(). If the area pointed to was moved, a free(oaddr) is done.
    886902        void * resize( void * oaddr, size_t size ) {
     903                #ifdef __STATISTICS__
     904                __atomic_add_fetch( &resize_calls, 1, __ATOMIC_SEQ_CST );
     905                #endif // __STATISTICS__
     906
    887907                // 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
    895                 #ifdef __STATISTICS__
    896                 __atomic_add_fetch( &resize_calls, 1, __ATOMIC_SEQ_CST );
    897                 #endif // __STATISTICS__
    898 
     908          if ( unlikely( size == 0 ) ) { free( oaddr ); return 0p; } // special cases
    899909          if ( unlikely( oaddr == 0p ) ) {
    900910                        #ifdef __STATISTICS__
     
    908918                size_t bsize, oalign;
    909919                headers( "resize", oaddr, header, freeElem, bsize, oalign );
    910 
    911920                size_t odsize = dataStorage( bsize, oaddr, header ); // data storage available in bucket
     921
    912922                // same size, DO NOT preserve STICKY PROPERTIES.
    913923                if ( oalign == libAlign() && size <= odsize && odsize <= size * 2 ) { // allow 50% wasted storage for smaller size
     
    930940        // the old and new sizes.
    931941        void * realloc( void * oaddr, size_t size ) {
     942                #ifdef __STATISTICS__
     943                __atomic_add_fetch( &realloc_calls, 1, __ATOMIC_SEQ_CST );
     944                #endif // __STATISTICS__
     945
    932946                // 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
    940                 #ifdef __STATISTICS__
    941                 __atomic_add_fetch( &realloc_calls, 1, __ATOMIC_SEQ_CST );
    942                 #endif // __STATISTICS__
    943 
     947          if ( unlikely( size == 0 ) ) { free( oaddr ); return 0p; } // special cases
    944948          if ( unlikely( oaddr == 0p ) ) {
    945949                        #ifdef __STATISTICS__
     
    995999        void * memalign( size_t alignment, size_t size ) {
    9961000                #ifdef __STATISTICS__
    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
     1001                __atomic_add_fetch( &memalign_calls, 1, __ATOMIC_SEQ_CST );
     1002                __atomic_add_fetch( &memalign_storage, size, __ATOMIC_SEQ_CST );
    10031003                #endif // __STATISTICS__
    10041004
     
    10111011                size_t size = dim * elemSize;
    10121012                #ifdef __STATISTICS__
    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
     1013                __atomic_add_fetch( &cmemalign_calls, 1, __ATOMIC_SEQ_CST );
     1014                __atomic_add_fetch( &cmemalign_storage, size, __ATOMIC_SEQ_CST );
    10191015                #endif // __STATISTICS__
    10201016
     
    10251021        // Same as calloc() with memory alignment.
    10261022        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
    10341023                #ifdef __STATISTICS__
    10351024                __atomic_add_fetch( &cmemalign_calls, 1, __ATOMIC_SEQ_CST );
     
    10371026                #endif // __STATISTICS__
    10381027
    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;
     1028                return cmemalignNoStats( alignment, dim, elemSize );
    10601029        } // cmemalign
    10611030
     
    10961065        // 0p, no operation is performed.
    10971066        void free( void * addr ) {
     1067                #ifdef __STATISTICS__
     1068                __atomic_add_fetch( &free_calls, 1, __ATOMIC_SEQ_CST );
     1069                #endif // __STATISTICS__
     1070
    10981071          if ( unlikely( addr == 0p ) ) {                                       // special case
    1099                         #ifdef __STATISTICS__
    1100                         __atomic_add_fetch( &free_zero_calls, 1, __ATOMIC_SEQ_CST );
    1101                         #endif // __STATISTICS__
    1102 
    11031072                        // #ifdef __CFA_DEBUG__
    11041073                        // if ( traceHeap() ) {
     
    12131182        int malloc_stats_fd( int fd __attribute__(( unused )) ) {
    12141183                #ifdef __STATISTICS__
    1215                 int temp = stats_fd;
    1216                 stats_fd = fd;
     1184                int temp = stat_fd;
     1185                stat_fd = fd;
    12171186                return temp;
    12181187                #else
     
    12451214        // The string is printed on the file stream stream.  The exported string includes information about all arenas (see
    12461215        // malloc).
    1247         int malloc_info( int options, FILE * stream __attribute__(( unused )) ) {
     1216        int malloc_info( int options, FILE * stream ) {
    12481217          if ( options != 0 ) { errno = EINVAL; return -1; }
    12491218                #ifdef __STATISTICS__
     
    12741243// Must have CFA linkage to overload with C linkage realloc.
    12751244void * resize( void * oaddr, size_t nalign, size_t size ) {
    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
     1245        #ifdef __STATISTICS__
     1246        __atomic_add_fetch( &resize_calls, 1, __ATOMIC_SEQ_CST );
     1247        #endif // __STATISTICS__
    12841248
    12851249        if ( unlikely( nalign < libAlign() ) ) nalign = libAlign(); // reset alignment to minimum
    12861250        #ifdef __CFA_DEBUG__
    1287         else checkAlign( nalign );                                                      // check alignment
     1251        else
     1252                checkAlign( nalign );                                                   // check alignment
    12881253        #endif // __CFA_DEBUG__
    12891254
     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 cases
    12901257  if ( unlikely( oaddr == 0p ) ) {
    12911258                #ifdef __STATISTICS__
    1292                 __atomic_add_fetch( &resize_calls, 1, __ATOMIC_SEQ_CST );
    12931259                __atomic_add_fetch( &resize_storage, size, __ATOMIC_SEQ_CST );
    12941260                #endif // __STATISTICS__
     
    13361302
    13371303void * 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 
    13471304        if ( unlikely( nalign < libAlign() ) ) nalign = libAlign(); // reset alignment to minimum
    13481305        #ifdef __CFA_DEBUG__
    1349         else checkAlign( nalign );                                                      // check alignment
     1306        else
     1307                checkAlign( nalign );                                                   // check alignment
    13501308        #endif // __CFA_DEBUG__
    13511309
     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 cases
    13521312  if ( unlikely( oaddr == 0p ) ) {
    13531313                #ifdef __STATISTICS__
Note: See TracChangeset for help on using the changeset viewer.