Click here to Skip to main content
15,919,132 members
Home / Discussions / Algorithms
   

Algorithms

 
GeneralRe: And Or and Xor with floating point Pin
PIEBALDconsult25-Feb-09 6:48
mvePIEBALDconsult25-Feb-09 6:48 
QuestionCalculate intersection between arcs / lines and arc /arc Pin
sagaert21-Feb-09 8:12
sagaert21-Feb-09 8:12 
AnswerRe: Calculate intersection between arcs / lines and arc /arc Pin
Arash Partow21-Feb-09 16:40
Arash Partow21-Feb-09 16:40 
GeneralRe: Calculate intersection between arcs / lines and arc /arc Pin
sagaert22-Feb-09 3:13
sagaert22-Feb-09 3:13 
QuestionCaculate time left for data transfer Pin
cdpace17-Feb-09 6:21
cdpace17-Feb-09 6:21 
GeneralRe: Caculate time left for data transfer Pin
Luc Pattyn17-Feb-09 6:32
sitebuilderLuc Pattyn17-Feb-09 6:32 
GeneralRe: Caculate time left for data transfer Pin
cdpace17-Feb-09 11:30
cdpace17-Feb-09 11:30 
GeneralRe: Caculate time left for data transfer Pin
Luc Pattyn17-Feb-09 13:51
sitebuilderLuc Pattyn17-Feb-09 13:51 
Hi,

yeah, that's almost it although I have several comments:

1.
I would update downloadPercentage before the > 10 test, so the test uses the latest information.
That way you don't need isFirst at all.

2.
I explained using percentages for clarity, but you could as well use downloadFraction which would grow from zero to one, all it takes is to replace all the numbers 100 by 1 (and test for > 0.1).

3.
it does not make sense to handle minutes and seconds separately; the way you have it you are multiplying both minutes and seconds by a factor which initially is large (e.g. if you did 20% in 3 minutes 20 seconds, then the factor would be 4 and the estimate 12 minutes and 80 seconds). Choose one unit of time, probably seconds, and get the DateTime.Now.Subtract(starttime).TotalSeconds; after the multiplication you can have TimeSpan convert it back to minutes and seconds.

4.
new byte[65535] looks silly to me; in file I/O the underlying code favors powers of 2 (disk sectors and clusters are powers of 2 for a reason), so try and stick to those, use 65536 or 32768 or something similar (and write it as 0x00010000 or 0x8000 to make that clear). Chances are the stream does not care and will provide arbitrary amounts of data anyway, but when it happens to provide multiples of 512 bytes, the file I/O would benefit.

5.
there is no need to get a new byte[] for each iteration of the while loop, you could create it once
and reuse it.

6.
the sequence flush - close does not make much sense; close always implies flush; an explicit flush really only is useful when you want to make sure some data gets actually written to the file/stream
which you don't want to close yet, but might get lost if the app suddenly would crash.

7.
I am not sure what if (incomingNetworkStream.DataAvailable) is meant to do; I would hope your communication is event driven, or you use a separate thread and a blocking read...

8.
I suggest you use a big try-catch block, after all networking and file I/O sooner or later will fail for whatever peculiar reason a system can come up with.

That's all.

Smile | :)

Luc Pattyn [Forum Guidelines] [My Articles]

- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets


AnswerRe: Caculate time left for data transfer Pin
Leonardo Muzzi17-Feb-09 9:12
Leonardo Muzzi17-Feb-09 9:12 
Questionthinning algorithm Pin
Swati Khanna17-Feb-09 1:40
Swati Khanna17-Feb-09 1:40 
AnswerRe: thinning algorithm Pin
riced17-Feb-09 2:33
riced17-Feb-09 2:33 
AnswerRe: thinning algorithm Pin
Andrew Kirillov5-Mar-09 0:49
Andrew Kirillov5-Mar-09 0:49 
QuestionAES Rijndael Cryptography fails Pin
Leonardo Muzzi16-Feb-09 10:16
Leonardo Muzzi16-Feb-09 10:16 
GeneralRe: App fails to use AES Rijndael Cryptography correctly? Pin
Luc Pattyn16-Feb-09 10:41
sitebuilderLuc Pattyn16-Feb-09 10:41 
AnswerRe: App fails to use AES Rijndael Cryptography correctly? Pin
Leonardo Muzzi17-Feb-09 3:13
Leonardo Muzzi17-Feb-09 3:13 
QuestionCreating graph of file usage in build tree Pin
Adam Dare13-Feb-09 3:38
Adam Dare13-Feb-09 3:38 
AnswerRe: Creating graph of file usage in build tree Pin
ky_rerun24-Feb-09 15:16
ky_rerun24-Feb-09 15:16 
GeneralRe: Creating graph of file usage in build tree Pin
Adam Dare24-Feb-09 18:35
Adam Dare24-Feb-09 18:35 
GeneralRe: Creating graph of file usage in build tree Pin
ky_rerun24-Feb-09 20:24
ky_rerun24-Feb-09 20:24 
GeneralRe: Creating graph of file usage in build tree Pin
Adam Dare25-Feb-09 4:13
Adam Dare25-Feb-09 4:13 
Questionerror correction Pin
Deresen12-Feb-09 2:02
Deresen12-Feb-09 2:02 
AnswerRe: error correction Pin
Ravadre12-Feb-09 4:44
Ravadre12-Feb-09 4:44 
GeneralRe: error correction Pin
Deresen12-Feb-09 5:07
Deresen12-Feb-09 5:07 
GeneralRe: error correction Pin
Ravadre12-Feb-09 6:45
Ravadre12-Feb-09 6:45 
AnswerRe: error correction Pin
Arash Partow12-Feb-09 12:04
Arash Partow12-Feb-09 12:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.