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/ptrarray.c

    r7404 r7524  
    2020#define GROW 32
    2121
    22 struct tr_ptrArray
    23 {
    24     void ** items;
    25     int     n_items;
    26     int     n_alloc;
    27 };
     22const tr_ptrArray TR_PTR_ARRAY_INIT = { NULL, 0, 0 };
     23
     24void
     25tr_ptrArrayDestruct( tr_ptrArray * p, PtrArrayForeachFunc func )
     26{
     27    assert( p );
     28    assert( p->items || !p->n_items );
     29
     30    if( func )
     31        tr_ptrArrayForeach( p, func );
     32
     33    tr_free( p->items );
     34
     35    memset( p, ~0, sizeof( tr_ptrArray ) );
     36}
    2837
    2938tr_ptrArray*
    3039tr_ptrArrayNew( void )
    3140{
    32     tr_ptrArray * p;
    33 
    34     p = tr_new( tr_ptrArray, 1 );
    35     p->n_items = 0;
    36     p->n_alloc = 0;
    37     p->items = NULL;
    38 
     41    tr_ptrArray * p = tr_new( tr_ptrArray, 1 );
     42    *p = TR_PTR_ARRAY_INIT;
    3943    return p;
    4044}
     
    7074                 PtrArrayForeachFunc func )
    7175{
    72     assert( t );
    73     assert( t->items || !t->n_items );
    74 
    75     if( func )
    76         tr_ptrArrayForeach( t, func );
    77 
    78     tr_free( t->items );
     76    tr_ptrArrayDestruct( t, func );
    7977    tr_free( t );
    8078}
Note: See TracChangeset for help on using the changeset viewer.