Ignore:
Timestamp:
Jan 23, 2000, 4:20:53 AM (26 years ago)
Author:
bird
Message:

Initial resident heap coding completed.
The AVL heap is seems to be much faster; it uses 40% of the time that the
traditional linked-list based heap is using when executing the heaptest.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/win32k/misc/heaptest.c

    r2501 r2503  
    1 /* $Id: heaptest.c,v 1.1 2000-01-22 18:21:03 bird Exp $
     1/* $Id: heaptest.c,v 1.2 2000-01-23 03:20:52 bird Exp $
    22 *
    33 * Test of resident and swappable heaps.
     
    1313*   Defined Constants
    1414*******************************************************************************/
    15 #define NUMBER_OF_POINTERS      10240
    16 #define RANDOMTEST_ITERATIONS   10240
     15#define NUMBER_OF_POINTERS      16384
     16#define RANDOMTEST_ITERATIONS   65536*2
     17#define Int3()          __interrupt(3)
    1718
    1819
     
    2223#include "malloc.h"
    2324#include "rmalloc.h"
     25#include "macros.h"
    2426#include <stdio.h>
    2527#include <stdlib.h>
     28#include <memory.h>
     29#include <builtin.h>
    2630
    2731
     
    3640    unsigned      crmalloc;
    3741    unsigned      crfree;
    38 
     42    unsigned      crealloc;
    3943    int           i;
    4044
     
    5458 *
    5559 */
     60#if 1
    5661    /*
    5762     * Simple allocation test.
     
    6267        {
    6368            acb[i] = rand();
    64         } while(acb[i] == 0 || acb[i] > 64);
    65 
     69        } while(acb[i] == 0 || acb[i] > 127);
     70
     71        if ((i % (NUMBER_OF_POINTERS/3)) == 1)
     72            acb[i] += 1024*260;
    6673        apv[i] = rmalloc(acb[i]);
    6774        if (apv[i] == NULL)
     
    7178                break;
    7279        }
     80        memset(apv[i], 0xA, MIN(acb[i],16));
    7381        cb += acb[i];
    7482    }
     
    8391    {
    8492        int cb = _res_msize(apv[i]);
    85         if (cb != ((acb[i] + 3) & ~3) && (cb < ((acb[i] + 3) & ~3) || cb > 40 + ((acb[i] + 3) & ~3)) )
     93        if (cb != ((acb[i] + 3) & ~3) && (cb < ((acb[i] + 3) & ~3) || cb > 52 + ((acb[i] + 3) & ~3)) )
    8694            printf("size of avp[%d] (%d) != acb[%] (%d)\n", i, cb, i, acb[i]);
    8795        rfree(apv[i]);
     
    101109    printf("\n_res_dump_subheaps:\n");
    102110    _res_dump_subheaps();
     111#endif
    103112
    104113
     
    115124    crfree = 0;
    116125    crmalloc = 0;
     126    crealloc = 0;
    117127    while (i++ < RANDOMTEST_ITERATIONS || cAllocations > 0)
    118128    {
     
    120130        j = rand();
    121131        if (cAllocations + (NUMBER_OF_POINTERS/20) < NUMBER_OF_POINTERS &&
    122             (i < RANDOMTEST_ITERATIONS*1/4 ? (j % 8) > 1 :
    123              i < RANDOMTEST_ITERATIONS*2/4 ? (j % 8) > 2 :
    124              i < RANDOMTEST_ITERATIONS*3/4 ? (j % 8) > 3 :
     132            (i < RANDOMTEST_ITERATIONS*1/4 ? (j % 8) > 2 :
     133             i < RANDOMTEST_ITERATIONS*2/4 ? (j % 8) > 3 :
     134             i < RANDOMTEST_ITERATIONS*3/4 ? (j % 8) > 4 :
    125135             i < RANDOMTEST_ITERATIONS     ? (j % 8) > 5 : 0
    126136             )
     
    134144                {
    135145                    acb[j] = rand();
    136                 } while (acb[j] == 0 || acb[j] > 2048);
     146                } while (acb[j] == 0 || (acb[j] > 2048 && (i % 11) != 10));
     147                if ((i % (RANDOMTEST_ITERATIONS/20)) == 1)
     148                    acb[j] += 1024*256;
    137149                apv[j] = rmalloc(acb[j]);
    138150                if (apv[j] == NULL)
     
    141153                    if (acb[j] > 10000)
    142154                        continue;
    143                 }
     155                    break;
     156                }
     157                memset(apv[j], 0xA, MIN(acb[j],16));
    144158                cAllocations++;
    145159                cb += acb[j];
     
    148162        }
    149163        else
    150         { /* free */
     164        { /* free or realloc */
    151165            if (cAllocations == 0)
    152166                continue;
     167
    153168            if (cAllocations < NUMBER_OF_POINTERS/10)
    154169            {
     
    162177                {
    163178                    j = rand();
    164                 } while (k < NUMBER_OF_POINTERS/2 && (j >= NUMBER_OF_POINTERS || apv[j] == NULL));
     179                } while (k++ < NUMBER_OF_POINTERS/2 && (j >= NUMBER_OF_POINTERS || apv[j] == NULL));
    165180                if (k >= NUMBER_OF_POINTERS/2)
    166181                {
     
    173188            {
    174189                int cb = _res_msize(apv[j]);
    175                 if (cb != ((acb[j] + 3) & ~3) && (cb < ((acb[j] + 3) & ~3) || cb > 40 + ((acb[j] + 3) & ~3)) )
     190                if (cb != ((acb[j] + 3) & ~3) && (cb < ((acb[j] + 3) & ~3) || cb > 52 + ((acb[j] + 3) & ~3)) )
    176191                    printf("size of avp[%d] (%d) != acb[%d] (%d)\n", j, cb, j, acb[j]);
    177                 rfree(apv[j]);
    178                 apv[j] = NULL;
    179                 cAllocations--;
    180                 crfree++;
     192                if (i < RANDOMTEST_ITERATIONS*3/4 && j % 3 == 0)
     193                {   /* realloc */
     194                    int cb;
     195                    void *pv;
     196                    crealloc++;
     197                    do
     198                    {
     199                        cb = rand();
     200                    } while (cb == 0 || cb > 3072);
     201                    /*
     202                    if (i >= 0x1c14)
     203                        Int3();
     204                    */
     205                    pv = rrealloc(apv[j], cb);
     206                    if (pv == NULL)
     207                    {
     208                        printf("realloc(apv[%d](0x%08), %d) failed\n", j, apv[j], cb);
     209                        continue;
     210                    }
     211                    apv[j] = pv;
     212                    acb[j] = cb;
     213                }
     214                else
     215                {   /* free */
     216                    rfree(apv[j]);
     217                    apv[j] = NULL;
     218                    cAllocations--;
     219                    crfree++;
     220                }
    181221            }
    182222        }
    183         _res_heap_check();
    184         if (RANDOMTEST_ITERATIONS == i*2)
     223        /*_res_heap_check();*/
     224        if (RANDOMTEST_ITERATIONS/2 == i)
    185225            _res_dump_subheaps();
    186     }
    187 
    188     printf("cb=%d crfree=%d crmalloc=%d\n", cb, crfree, crmalloc);
     226        if ((i % 2048) == 0)
     227            printf("i=%d cAllocations=%d\n", i, cAllocations);
     228    }
     229
     230    printf("cb=%d crfree=%d crmalloc=%d crealloc=%d\n", cb, crfree, crmalloc, crealloc);
    189231
    190232    printf("_res_dump_subheaps:\n");
Note: See TracChangeset for help on using the changeset viewer.