On Sun, May 01, 2005 at 06:31:29PM -0700, Kevin P. Fleming wrote:
> The recent UTF-8 discussion brought to light something that I had not 
> realized before... strncpy() zero-fills the destination buffer, which is 
> waste of time (and cache pollution). In Asterisk, we are nearly always 
> copying strings into buffers that are much larger than required, so this 
> extra zero-writing is just wasted CPU cycles.

There is one popular strncpy alternative that doesn't seem to do this
padding: strlcpy

  http://www.courtesan.com/todd/papers/strlcpy.html

[ snip ]

> I do understand that GCC has a highly-optimized strncpy implementation 
> for each architecture it runs on, and I don't doubt that an open-coded 
> version will not be optimized as well. However, we'd be trading a 
> slightly slower implementation against not writing many, many billions 
> of excess zero bytes over the lifetime of an Asterisk instance.
> 
> Thoughts?

Consider using strlcpy? Maybe it has already been optimized?

-- 
Tzafrir Cohen     icq#16849755  +972-50-7952406
[EMAIL PROTECTED]  http://www.xorcom.com
_______________________________________________
Asterisk-Dev mailing list
[email protected]
http://lists.digium.com/mailman/listinfo/asterisk-dev
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-dev

Reply via email to