abcdlcq的个人主页

http://www.qtcn.org/bbs/u/118073  [收藏] [复制]

abcdlcq

  • 13

    关注

  • 15

    粉丝

  • 38

    访客

  • 等级:新手上路
  • 总积分:83
  • 男,1984-01-01

最后登录:2017-09-29

更多资料

日志

QDataStream::readBytes和QDataStream::readRawBytes【转】

2012-11-20 17:37
Qt的参考文档中关于这两个函数的说明如下
http://doc.trolltech.com/3.3/qdatastream.html#readBytes

QDataStream & QDataStream::readBytes ( char *& s, uint & l )

Reads the buffer s from the stream and returns a reference to the stream.
The buffer s is allocated using new. Destroy it with the delete[] operator. If the length is zero or s cannot be allocated, s is set to 0.
The l parameter will be set to the length of the buffer.
The serialization format is a Q_UINT32 length specifier first, then l bytes of data. Note that the data is not encoded.
See also readRawBytes() and writeBytes().


QDataStream & QDataStream::readRawBytes ( char * s, uint len )
Reads len bytes from the stream into s and returns a reference to the stream.
The buffer s must be preallocated. The data is not encoded.
See also readBytes(), QIODevice::readBlock(), and writeRawBytes().
两个函数的区别:
     readBytes函数的形参不必自己申请空间,函数内部会new出一个空间(注意形参是一个指针的引用),并且这个函数我估计会读出流的所有,并把读出的字符长度赋给l。
而readRawBytes函数则需要先申请一段空间,并指定好读出的字符长度len。
ps:之前误认为用readBytes函数要先自己申请一段空间给s,每次readBytes前我都申请一段空间,程序跑起来内存升的厉害,终于发现了这个问题。
分类:默认分类|回复:0|浏览:2347|全站可见|转载
 

下一篇:

上一篇: C/C++项目中的代码复用和管理【转】

Powered by phpwind v8.7 Certificate Copyright Time now is:05-07 03:36
©2005-2016 QTCN开发网 版权所有 Gzip disabled