Visit our Sponsor   Visit our Sponsor
delphi3000.com - the free delphi knowledge platform
delphi3000.com - the free delphi knowledge platform
Have a look at your member-status

connecting people's knowledge


  - Recent ArticlesRSS feed for Recent Articles on delphi3000.com
  - List of All Articles
  - Top Viewed Articles
  - Articles (+Attachem.)
  - Articles Of Interest
  - Categories
  - Top Uploader
  - Search
  - Index

  - My Home
  - Submit an Article
  - My Articles
  - My Personal Data
  - My Bookmarks
  - Activities
  - Login/Logout

  - Sign Up
  - Why Sign Up
  - Newsletter

  - Press
  - Advertise

  - Contact
  - Feedback





Community
Borland
ClubeDelphi
Dr. Bob
UK-BUG
Delphi Meetings
Planeta Delphi







Startblatt.de






Share this article with friendsShare this article with friends
Rate this articleRate this article - to keep the quality of delphi3000.com !
Comment this article or read through previous comments (0)


Quick untyped fileaccessFormat this article printer-friendly!Bookmark function is only available for registered users!
Product:
Delphi all versions
Category:
Files Operation
Skill Level:
Scoring:
Last Update:
10/27/2002
Search Keys:
delphi delphi3000 article borland vcl code-snippet Quick untyped fileaccess TAdvancedFileStream
Times Scored:
3
Visits:
1635
Uploader: DenShade Hyp
Company:
Reference: www25.brinkster.com/denshade
 
Question/Problem/Abstract:
How can we read quickly from an untyped file consisting out of bytes without making the code complicated ?
Answer:



Sometimes we have to read from files by handling byte by byte.
Experience shows that reading byte by byte from a TFileStream or whatever variant that can read files does so slowly.

The cause is simple. The harddisk needs to find the location on the hdd each time you request a read from a file. I have been working with compression and sometimes the programs demanded actual hours to simply read a file...

This problem is solved pretty easily by reading not in bytes but in huger
chunks of data and adapting your programme to this new structure.
eg.
FFile : TFileStream;
bbyte : byte;
buffer : array[0..65535] of byte;
...
FFile.read(bbyte,1); //the slow way to do it, but little complex
FFile.read(buffer,65536);
//reads much faster but handling each byte must be done in some kind of loop.

As you would work with the buffer you would soon see that this method is faster.
On my machine I tested it on 600MB, the byte by byte reading method required
several hours while reading the buffers 13 minutes.


In order to reduce complexity in using this buffer I have made a class
that does all this for you.(making the buffer, reading if the buffer is completely worked through)I call it the TAdvancedMemoryStream.

Implementing this will allow the simplicity to read each and every byte sequentially.

FileReader : TAdvancedFileStream;
b : byte;

b := FileReader.readByte;

The FileReader will automatically use a buffer and due too it's simplicity this
class can only be recommended if you wish to read bytes sequentially and doing so in the fastest and simplest way available.

The .pas file can be downloaded from my site :

www25.brinkster.com/denshade

Mind though that the current version at 27/10/2002 only supports reading bytes and retreiving the position.

If you have remarks or you have found a huge bug in the code you could drop
by a mail at denshade@hotmail.com...even though the chances that i find your mail between all the junkmail is fairly little. My mailbox is set to selective
so if you do try to mail me, mention the component in the title.

I hope this is somehow usefull for someone,
DS





Please rate this article!
Skill level:
BeginnerExpert

Useful:
No!Very!

Overall rating:
PoorExcellent



Comments to this article
Write a new comment













 
Sign up to consume product discounts for Bronze memberships !

read more


  Visit our Sponsor

 

  Community Ad of
D. Wischnewski
 
   














 







     
  Copyright © 2000 - 2007 delphi3000.com - All rights reserved. Terms of use. || Privacy
delphi3000.com is a service by bluestep.com IT-Services GmbH (Vienna)