Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 4

Qt-interest Archive, June 2007
what is better


Message 1 in thread

Hi,
  can you advise me, what is better to use?

1. with reading loop (while)
QByteArray getMD5Sum(const QString & path)
{
	QFile file(path);

	QCryptographicHash md5Hash(QCryptographicHash::Md5);

	if (file.open(QIODevice::ReadOnly | QIODevice::Unbuffered)) {		
		while (!file.atEnd())
			md5Hash.addData(file.read(10485760));

	}

	filr.close();

	return md5Hash.result();
}

2. without reading loop
QByteArray getMD5Sum(const QString & path)
{
	QFile file(path);

	QCryptographicHash md5Hash(QCryptographicHash::Md5);

	if (file.open(QIODevice::ReadOnly | QIODevice::Unbuffered)) {		
		md5Hash.addData(file.readAll());

	}

	filr.close();

	return md5Hash.result();
}

Thank you for your opinions.

-- 
 [ signature omitted ] 

Message 2 in thread

Well.. considering your reading in 10 megs at a time... I don't know if
its going to make too much of a difference.

But I recommend using readAll... It uses a loop as well (always check
the code :) ) however, it does some progressive growth of the amount of
data each time to try and optimize the reading.

Also, it knows about if the file is sequential, if it knows the number
of bytes available etc etc....


In general, when you try to implement an algorithm using a class, that
already is implemented by a method of the same class, I then to use the
existing method... Simply since it tends to make it easier to read and
maintain

Scott

> -----Original Message-----
> From: kAja Ziegler [mailto:ziegleka@xxxxxxxxx]
> Sent: Monday, June 18, 2007 1:44 AM
> To: qt-interest@xxxxxxxxxxxxx
> Subject: what is better
> 
> Hi,
>   can you advise me, what is better to use?
> 
> 1. with reading loop (while)
> QByteArray getMD5Sum(const QString & path)
> {
> 	QFile file(path);
> 
> 	QCryptographicHash md5Hash(QCryptographicHash::Md5);
> 
> 	if (file.open(QIODevice::ReadOnly | QIODevice::Unbuffered)) {
> 
> 		while (!file.atEnd())
> 			md5Hash.addData(file.read(10485760));
> 
> 	}
> 
> 	filr.close();
> 
> 	return md5Hash.result();
> }
> 
> 2. without reading loop
> QByteArray getMD5Sum(const QString & path)
> {
> 	QFile file(path);
> 
> 	QCryptographicHash md5Hash(QCryptographicHash::Md5);
> 
> 	if (file.open(QIODevice::ReadOnly | QIODevice::Unbuffered)) {
> 
> 		md5Hash.addData(file.readAll());
> 
> 	}
> 
> 	filr.close();
> 
> 	return md5Hash.result();
> }
> 
> Thank you for your opinions.
> 
> --
> Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
> 
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/

--
 [ signature omitted ] 

Message 3 in thread

> > But I recommend using readAll... It uses a loop as well (always
check
> > the code :) ) however, it does some progressive growth of the amount
of
> > data each time to try and optimize the reading.
> 
> What if opened file is DVD-image (4.5 or even 9 GB)?
> Explicit loop and loading only few MBytes is better IMHO.
> 
> --
> Ivan Kharin

Please don't contact me directly....

You are correct... except... it would be very unlikely, that you're
going to want to store the complete 4.5 GB file into a ByteArray, thus
you not wanting to duplicate the readAll...

The OP, because he was computing the Crypographic Hash of the data sent
in....  in reality, the 10MB was probably too big as well... but it
would depend on a bunch of cache sizes in the system.  

I think it would also depend on the speed of the IO device... slower the
speed, the more likely I would want to use a custom loop (so I could
create an singleShot timer based loop.

Scott
 

--
 [ signature omitted ] 

Message 4 in thread

>> What if opened file is DVD-image (4.5 or even 9 GB)?
>> Explicit loop and loading only few MBytes is better IMHO.
>> 
>> --
>> Ivan Kharin

> Please don't contact me directly....

Sorry, forgot to change "to:" clause.

> The OP, because he was computing the Crypographic Hash of the data sent
> in....  in reality, the 10MB was probably too big as well... but it
> would depend on a bunch of cache sizes in the system.

Currently i verify DVD-image uploaded to our web-server by checking MD5-sum.

> I think it would also depend on the speed of the IO device... slower the
> speed, the more likely I would want to use a custom loop (so I could
> create an singleShot timer based loop.

Or use work thread instead.


-- 
 [ signature omitted ] 

Message 5 in thread

So that, the first concept is better for bigger files?

On Mon, 18 Jun 2007 12:08:48 +0200, Scott Aron Bloom <scott@xxxxxxxxxxxx>  
wrote:

>> > But I recommend using readAll... It uses a loop as well (always
> check
>> > the code :) ) however, it does some progressive growth of the amount
> of
>> > data each time to try and optimize the reading.
>>
>> What if opened file is DVD-image (4.5 or even 9 GB)?
>> Explicit loop and loading only few MBytes is better IMHO.
>>
>> --
>> Ivan Kharin
>
> Please don't contact me directly....
>
> You are correct... except... it would be very unlikely, that you're
> going to want to store the complete 4.5 GB file into a ByteArray, thus
> you not wanting to duplicate the readAll...
>
> The OP, because he was computing the Crypographic Hash of the data sent
> in....  in reality, the 10MB was probably too big as well... but it
> would depend on a bunch of cache sizes in the system.
>
> I think it would also depend on the speed of the IO device... slower the
> speed, the more likely I would want to use a custom loop (so I could
> create an singleShot timer based loop.
>
> Scott
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with  
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/



-- 
 [ signature omitted ] 

Message 6 in thread

Probably

> -----Original Message-----
> From: kAja Ziegler [mailto:ziegleka@xxxxxxxxx]
> Sent: Monday, June 18, 2007 8:45 AM
> To: qt-interest@xxxxxxxxxxxxx
> Subject: Re: what is better
> 
> So that, the first concept is better for bigger files?
> 
> On Mon, 18 Jun 2007 12:08:48 +0200, Scott Aron Bloom
<scott@xxxxxxxxxxxx>
> wrote:
> 
> >> > But I recommend using readAll... It uses a loop as well (always
> > check
> >> > the code :) ) however, it does some progressive growth of the
amount
> > of
> >> > data each time to try and optimize the reading.
> >>
> >> What if opened file is DVD-image (4.5 or even 9 GB)?
> >> Explicit loop and loading only few MBytes is better IMHO.
> >>
> >> --
> >> Ivan Kharin
> >
> > Please don't contact me directly....
> >
> > You are correct... except... it would be very unlikely, that you're
> > going to want to store the complete 4.5 GB file into a ByteArray,
thus
> > you not wanting to duplicate the readAll...
> >
> > The OP, because he was computing the Crypographic Hash of the data
sent
> > in....  in reality, the 10MB was probably too big as well... but it
> > would depend on a bunch of cache sizes in the system.
> >
> > I think it would also depend on the speed of the IO device... slower
the
> > speed, the more likely I would want to use a custom loop (so I could
> > create an singleShot timer based loop.
> >
> > Scott
> >
> > --
> > To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx
with
> > "unsubscribe" in the subject or the body.
> > List archive and information:
http://lists.trolltech.com/qt-interest/
> 
> 
> 
> --
> Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
> 
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/

--
 [ signature omitted ] 

Message 7 in thread

kAja Ziegler wrote:
> So that, the first concept is better for bigger files?

Absolutely. The readAll() method will read the ENTIRE file into one big 
block of memory. You probably don't have 4GB of memory, or even virtual 
memory, available to you, so that's not very helpful if your files are DVDs.

If the file is on disk, then it's probably already buffered. So you 
could get away with reading 4K or 8K blocks, one at a time, with little 
or no overhead. Or, since your files are so big, 1MB blocks might be 
more appropriate.

> 
> On Mon, 18 Jun 2007 12:08:48 +0200, Scott Aron Bloom 
> <scott@xxxxxxxxxxxx> wrote:
> 
>>> > But I recommend using readAll... It uses a loop as well (always
>> check
>>> > the code :) ) however, it does some progressive growth of the amount
>> of
>>> > data each time to try and optimize the reading.
>>>
>>> What if opened file is DVD-image (4.5 or even 9 GB)?
>>> Explicit loop and loading only few MBytes is better IMHO.
>>>
>>> -- 
>>> Ivan Kharin
>>
>> Please don't contact me directly....
>>
>> You are correct... except... it would be very unlikely, that you're
>> going to want to store the complete 4.5 GB file into a ByteArray, thus
>> you not wanting to duplicate the readAll...
>>
>> The OP, because he was computing the Crypographic Hash of the data sent
>> in....  in reality, the 10MB was probably too big as well... but it
>> would depend on a bunch of cache sizes in the system.
>>
>> I think it would also depend on the speed of the IO device... slower the
>> speed, the more likely I would want to use a custom loop (so I could
>> create an singleShot timer based loop.
>>
>> Scott
>>
>> -- 
>> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with 
>> "unsubscribe" in the subject or the body.
>> List archive and information: http://lists.trolltech.com/qt-interest/
> 
> 
> 


-- 
 [ signature omitted ]