Ignore:
Timestamp:
Dec 29, 2008, 9:51:54 AM (13 years ago)
Author:
charles
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/utils.c

    r7446 r7525  
    747747
    748748tr_bitfield*
     749tr_bitfieldConstruct( tr_bitfield * b, size_t bitCount )
     750{
     751    b->bitCount = bitCount;
     752    b->byteCount = ( bitCount + 7u ) / 8u;
     753    b->bits = tr_new0( uint8_t, b->byteCount );
     754    return b;
     755}
     756
     757void
     758tr_bitfieldDestruct( tr_bitfield * b )
     759{
     760    tr_free( b->bits );
     761}
     762
     763tr_bitfield*
    749764tr_bitfieldNew( size_t bitCount )
    750765{
    751     tr_bitfield * ret = tr_new0( tr_bitfield, 1 );
    752 
    753     ret->bitCount = bitCount;
    754     ret->byteCount = ( bitCount + 7u ) / 8u;
    755     ret->bits = tr_new0( uint8_t, ret->byteCount );
    756     return ret;
     766    return tr_bitfieldConstruct( tr_new0( tr_bitfield, 1 ), bitCount );
    757767}
    758768
     
    773783    if( bitfield )
    774784    {
    775         tr_free( bitfield->bits );
     785        tr_bitfieldDestruct( bitfield );
    776786        tr_free( bitfield );
    777787    }
Note: See TracChangeset for help on using the changeset viewer.