Changeset 12381


Ignore:
Timestamp:
Apr 27, 2011, 5:03:10 AM (10 years ago)
Author:
jordan
Message:

(trunk libT) #4209 "Shortcut UDP tracker test" -- the goal of #4209 is to minimize the cost of the UDP event callback function, so apply the heap pruning eye to that by removing an unnecessary malloc/free call there.

Previously we allocated a 4096 character buffer each time; now we allocate it on the stack. It seems all the distros and OS flavors that Transmission runs on have multi-MB default stack sizes, so a hardwired 4K array should be safe.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/tr-udp.c

    r12378 r12381  
    189189{
    190190    tr_session *ss = sv;
    191     unsigned char *buf;
     191    unsigned char buf[4096];
    192192    struct sockaddr_storage from;
    193193    socklen_t fromlen;
     
    196196    assert(tr_isSession(sv));
    197197    assert(type == EV_READ);
    198 
    199     buf = malloc(4096);
    200     if(buf == NULL) {
    201         tr_nerr("UDP", "Couldn't allocate buffer");
    202         return;
    203     }
    204198
    205199    fromlen = sizeof(from);
     
    229223        }
    230224    }
    231 
    232     free(buf);
    233225}
    234226
Note: See TracChangeset for help on using the changeset viewer.