Annotation of parser3/src/targets/cgi/pa_pool.C, revision 1.6

1.4       paf         1: /** @file
                      2:        Parser: CGI memory manager impl.
                      3: 
1.1       paf         4:        Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
1.4       paf         5: 
1.1       paf         6:        Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
                      7: 
1.6     ! parser      8:        $Id: pa_pool.C,v 1.5 2001/05/15 10:48:53 parser Exp $
1.1       paf         9: */
                     10: 
                     11: #include <stdlib.h>
                     12: 
                     13: #include "pa_pool.h"
                     14: 
1.6     ! parser     15: #include "pa_sapi.h"
        !            16: #include "pa_common.h"
        !            17: #define MALLOC_STAT_MAXSIZE (0x400*0x400)
        !            18: #define MALLOC_STAT_PIECES MALLOC_STAT_MAXSIZE
        !            19: ///(10*1000*10*5)
        !            20: int malloc_size[MALLOC_STAT_PIECES];
        !            21: int malloc_times[MALLOC_STAT_PIECES];
        !            22: 
        !            23: void log_pool_stats(Pool& pool) {
        !            24:        for(int i=0; i<MALLOC_STAT_PIECES; i++)
        !            25:                if(malloc_times[i]) 
        !            26:                        SAPI::log(pool, 
        !            27:                                "%10d..%10d: %10d/%10d=%10d", 
        !            28:                                MALLOC_STAT_MAXSIZE/MALLOC_STAT_PIECES*(i), 
        !            29:                                MALLOC_STAT_MAXSIZE/MALLOC_STAT_PIECES*(1+i),
        !            30:                                malloc_size[i], malloc_times[i], malloc_size[i]/malloc_times[i]);
        !            31: }
1.5       parser     32: 
1.1       paf        33: void *Pool::real_malloc(size_t size) {
1.6     ! parser     34:        int index=min(MALLOC_STAT_PIECES-1, 
        !            35:                ((double)size)/MALLOC_STAT_MAXSIZE*MALLOC_STAT_PIECES);
        !            36:        malloc_size[index]+=size;
        !            37:        malloc_times[index]++;
1.1       paf        38:        return ::malloc(size);
                     39: }
                     40: 
                     41: void *Pool::real_calloc(size_t size) {
                     42:        return ::calloc(size, 1);
                     43: }

E-mail: