C-bzero和memset的效率问题
memset(&seraddr, 0, sizeof(seraddr));
//bzero(&seraddr, sizeof(seraddr));
seraddr.sin_family = AF_INET;
seraddr.sin_port = htons(SERVER_PORT);
seraddr.sin_addr.s_addr = htonl(INADDR_ANY);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
一样啦。想少敲几个按键就用 bzero 吧
These two functions have been historically been used in an interchangable manner, the reason being the nature of UNIX and its vastness. bzero() was originally a part of the BSD-Unix, and memset() was a part of the AT&T Unix. And later memset() was also adopted in the ANSI C and POSIX standards whereas bzero() was depracated. And while writing professional codes it is not advisable to use bzero() and longer, instead memset() should be used. (Although both will remain to be supported in the all the platforms).
参考链接:bzero-and-memset
用bzero()可以减少出错的几率,我就犯过将memset()将2,3参数搞反的错误。
一样的。只是memset能初始化为其他值。bzero是初始化为0。如果是初始化为0,bzero的语义更明确,而且更不容易出错。