在 Fri, 27 Jul 2012 21:40:25 +0800,Fabian Keil  
<[email protected]> 写道:

> ir193 <[email protected]> wrote:
>
>> I'm new here and seldom use mail list. Please tell me if I did something
>> improper.
>> Now I'm learning ansi C and socket programming these days. I read polipo
>> source code and saw this (in event.c):
>>
>> /* Let the compiler optimise the common cases */
>> if(dsize == sizeof(void*))
>>      memcpy(event->data, data, sizeof(void*));
>> else if(dsize == sizeof(StreamRequestRec))
>>      memcpy(event->data, data, sizeof(StreamRequestRec));
>> else if(dsize > 0)
>>      memcpy(event->data, data, dsize);
>>
>> I really don't understand why this is a "optimise". I'll appreciate if
>> someone can help.
>
> sizeof(void*) and sizeof(StreamRequestRec) are known at compile
> time so the compiler is free to replace the first two memcpy calls
> with more efficient code that has the same effect but only works
> with fixed lengths.
>
> I wouldn't recommend that you use similar constructs in your own code
> unless you have measured the difference and are sure it matters.
>
> Fabian

I got it. Well, I think I got it : )
Thank you very much for your reply. And thanks to Nix, too

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Polipo-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/polipo-users

Reply via email to