Ignore:
Timestamp:
Dec 29, 2008, 8:54:36 AM (12 years ago)
Author:
charles
Message:

(trunk libT) avoid some unnecessary memory fragmentation... for composited objects that have a tr_ptrArray, contain the tr_ptrArray directly rather than a pointer to one allocated elsewhere on the heap.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/bandwidth.c

    r7495 r7524  
    9999    int magicNumber;
    100100    tr_session * session;
    101     tr_ptrArray * children; /* struct tr_bandwidth */
    102     tr_ptrArray * peers; /* tr_peerIo */
     101    tr_ptrArray children; /* struct tr_bandwidth */
     102    tr_ptrArray peers; /* tr_peerIo */
    103103};
    104104
     
    131131    tr_bandwidth * b = tr_new0( tr_bandwidth, 1 );
    132132    b->session = session;
    133     b->children = tr_ptrArrayNew( );
    134     b->peers = tr_ptrArrayNew( );
     133    b->children = TR_PTR_ARRAY_INIT;
     134    b->peers = TR_PTR_ARRAY_INIT;
    135135    b->magicNumber = MAGIC_NUMBER;
    136136    b->band[TR_UP].honorParentLimits = TRUE;
     
    146146
    147147    tr_bandwidthSetParent( b, NULL );
    148     tr_ptrArrayFree( b->peers, NULL );
    149     tr_ptrArrayFree( b->children, NULL );
     148    tr_ptrArrayDestruct( &b->peers, NULL );
     149    tr_ptrArrayDestruct( &b->children, NULL );
    150150    b->magicNumber = 0xDEAD;
    151151    tr_free( b );
     
    167167        assert( tr_isBandwidth( b->parent ) );
    168168
    169         tr_ptrArrayRemoveSorted( b->parent->children, b, comparePointers );
     169        tr_ptrArrayRemoveSorted( &b->parent->children, b, comparePointers );
    170170        b->parent = NULL;
    171171    }
     
    176176        assert( parent->parent != b );
    177177
    178         tr_ptrArrayInsertSorted( parent->children, b, comparePointers );
     178        tr_ptrArrayInsertSorted( &parent->children, b, comparePointers );
    179179        b->parent = parent;
    180180    }
     
    270270    {
    271271        int i;
    272         const int n = tr_ptrArraySize( b->peers );
     272        const int n = TR_PTR_ARRAY_LENGTH( &b->peers );
    273273        for( i=0; i<n; ++i )
    274             tr_ptrArrayAppend( peer_pool, tr_ptrArrayNth( b->peers, i ) );
     274            tr_ptrArrayAppend( peer_pool, tr_ptrArrayNth( &b->peers, i ) );
    275275    }
    276276
     
    282282    /* all children should reallocate too */
    283283    if( 1 ) {
    284         int i, n=0;
    285         struct tr_bandwidth ** children = (struct tr_bandwidth**) tr_ptrArrayPeek( b->children, &n );
     284        int i;
     285        struct tr_bandwidth ** children = (struct tr_bandwidth**) TR_PTR_ARRAY_DATA( &b->children );
     286        const int n = TR_PTR_ARRAY_LENGTH( &b->children );
    286287        for( i=0; i<n; ++i )
    287288            allocateBandwidth( children[i], dir, period_msec, peer_pool );
     
    295296{
    296297    int i, n, peerCount;
    297     tr_ptrArray * tmp;
     298    tr_ptrArray tmp = TR_PTR_ARRAY_INIT;
    298299    struct tr_peerIo ** peers;
    299300    const uint64_t now = tr_date( );
     
    304305     * 1. allocate bandwidth to b and its subtree
    305306     * 2. accumulate an array of all the peerIos from b and its subtree. */
    306     tmp = tr_ptrArrayNew( );
    307     allocateBandwidth( b, dir, period_msec, tmp );
    308     peers = (struct tr_peerIo**) tr_ptrArrayPeek( tmp, &peerCount );
     307    allocateBandwidth( b, dir, period_msec, &tmp );
     308    peers = (struct tr_peerIo**) tr_ptrArrayPeek( &tmp, &peerCount );
    309309
    310310    /* Stop all peers from listening for the socket to be ready for IO.
     
    348348
    349349    /* cleanup */
    350     tr_ptrArrayFree( tmp, NULL );
     350    tr_ptrArrayDestruct( &tmp, NULL );
    351351}
    352352
     
    362362    assert( tr_isPeerIo( peerIo ) );
    363363
    364     tr_ptrArrayInsertSorted( b->peers, peerIo, comparePointers );
     364    tr_ptrArrayInsertSorted( &b->peers, peerIo, comparePointers );
    365365}
    366366
     
    372372    assert( tr_isPeerIo( peerIo ) );
    373373
    374     tr_ptrArrayRemoveSorted( b->peers, peerIo, comparePointers );
     374    tr_ptrArrayRemoveSorted( &b->peers, peerIo, comparePointers );
    375375}
    376376
Note: See TracChangeset for help on using the changeset viewer.