大佬教程收集整理的这篇文章主要介绍了c – 这个指针的memcpy是否安全?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
但是,我目前有这个拷贝构造函数:
// "obj" has the same type of *this,it's just another String object String_base<T>(const String_base<T> &obj) : len(obj.length()),cap(obj.capacity()) { raw_data = new T[cap]; for (unsigned i = 0; i < cap; i++) raw_data[i] = obj.data()[i]; raw_data[len] = 0x00; }
我想提高性能一点点.所以我想到使用memcpy()将obj复制到* this中.
就像那样:
// "obj" has the same type of *this,it's just another String object String_base<T>(const String_base<T> &obj) { memcpy(this,&obj,sizeof(String_base<T>)); }
是否可以安全地覆盖*这样的数据?或者这会产生任何问题吗?
提前致谢!
以上是大佬教程为你收集整理的c – 这个指针的memcpy是否安全?全部内容,希望文章能够帮你解决c – 这个指针的memcpy是否安全?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。