Ignore:
Timestamp:
Jan 2, 2009, 7:56:06 PM (12 years ago)
Author:
charles
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/bandwidth.c

    r7579 r7580  
    8282
    8383tr_bandwidth*
    84 tr_bandwidthNew( tr_session * session, tr_bandwidth * parent )
    85 {
    86     tr_bandwidth * b = tr_new0( tr_bandwidth, 1 );
     84tr_bandwidthConstruct( tr_bandwidth * b, tr_session * session, tr_bandwidth * parent )
     85{
    8786    b->session = session;
    8887    b->children = TR_PTR_ARRAY_INIT;
    89     b->peers = TR_PTR_ARRAY_INIT;
    9088    b->magicNumber = MAGIC_NUMBER;
    9189    b->band[TR_UP].honorParentLimits = TRUE;
     
    9593}
    9694
    97 void
    98 tr_bandwidthFree( tr_bandwidth * b )
     95tr_bandwidth*
     96tr_bandwidthDestruct( tr_bandwidth * b )
    9997{
    10098    assert( tr_isBandwidth( b ) );
    10199
    102100    tr_bandwidthSetParent( b, NULL );
    103     tr_ptrArrayDestruct( &b->peers, NULL );
    104101    tr_ptrArrayDestruct( &b->children, NULL );
    105102    b->magicNumber = 0xDEAD;
    106     tr_free( b );
     103
     104    return b;
    107105}
    108106
     
    134132        b->parent = parent;
    135133    }
    136 }
    137 
    138 void
    139 tr_bandwidthHonorParentLimits( tr_bandwidth  * b,
    140                                tr_direction    dir,
    141                                tr_bool         honorParentLimits )
    142 {
    143     assert( tr_isBandwidth( b ) );
    144     assert( tr_isDirection( dir ) );
    145 
    146     b->band[dir].honorParentLimits = honorParentLimits;
    147134}
    148135
     
    180167    }
    181168
    182     /* traverse & repeat for the subtree */
    183     {
    184         int i;
    185         const int n = TR_PTR_ARRAY_LENGTH( &b->peers );
    186         for( i=0; i<n; ++i )
    187             tr_ptrArrayAppend( peer_pool, tr_ptrArrayNth( &b->peers, i ) );
    188     }
     169    /* add this bandwidth's peer, if any, to the peer pool */
     170    if( b->peer != NULL )
     171        tr_ptrArrayAppend( peer_pool, b->peer );
    189172
    190173#ifdef DEBUG_DIRECTION
     
    193176#endif
    194177
    195     /* all children should reallocate too */
     178    /* traverse & repeat for the subtree */
    196179    if( 1 ) {
    197180        int i;
     
    217200     * 2. accumulate an array of all the peerIos from b and its subtree. */
    218201    allocateBandwidth( b, dir, period_msec, &tmp );
    219     peers = (struct tr_peerIo**) tr_ptrArrayPeek( &tmp, &peerCount );
     202    peers = (struct tr_peerIo**) TR_PTR_ARRAY_DATA( &tmp );
     203    peerCount = TR_PTR_ARRAY_LENGTH( &tmp );
    220204
    221205    /* Stop all peers from listening for the socket to be ready for IO.
     
    229213     * and/or peers that can use it */
    230214    n = peerCount;
     215#ifdef DEBUG_DIRECTION
     216if( dir == DEBUG_DIRECTION ) fprintf( stderr, "bandwidth.c: allocate: number of peerIos to go round-robin: %d\n", n );
     217#endif
    231218    i = n ? tr_cryptoWeakRandInt( n ) : 0; /* pick a random starting point */
    232219    while( n > 1 )
    233220    {
    234221        const int increment = 1024;
    235         const int bytesUsed = tr_peerIoFlush( peers[i], dir, increment);
     222        const int bytesUsed = tr_peerIoFlush( peers[i], dir, increment );
    236223
    237224        if( bytesUsed == increment )
     
    261248}
    262249
    263 /***
    264 ****
    265 ***/
    266 
    267250void
    268 tr_bandwidthAddPeer( tr_bandwidth   * b,
    269                      tr_peerIo      * peerIo )
    270 {
    271     assert( tr_isBandwidth( b ) );
    272     assert( tr_isPeerIo( peerIo ) );
    273 
    274 }
    275 
    276 void
    277 tr_bandwidthRemovePeer( tr_bandwidth  * b,
    278                         tr_peerIo     * peerIo )
    279 {
    280     assert( tr_isBandwidth( b ) );
    281     assert( tr_isPeerIo( peerIo ) );
    282 
    283     tr_ptrArrayRemoveSorted( &b->peers, peerIo, comparePointers );
     251tr_bandwidthSetPeer( tr_bandwidth * b, tr_peerIo * peer )
     252{
     253    assert( tr_isBandwidth( b ) );
     254    assert( ( peer == NULL ) || tr_isPeerIo( peer ) );
     255
     256    b->peer = peer;
    284257}
    285258
Note: See TracChangeset for help on using the changeset viewer.