Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

HELP!

1 view
Skip to first unread message

Tim Fries

unread,
Dec 18, 1994, 7:33:24 PM12/18/94
to

I've got a question for anyone who can answer it.
I'm updating a program that used to access a file on disk one byte at
a time. I've been looking for ways to speed up the program and the
frequency of disk accessing was my #1 concern. Anyway, instead of
reading byte by byte as it's needed, I thought I could read some
larger value, say 1K, into memory and use it from there, then read
another 1K from disk when the 1K in memory is used. Because the size
of the amount in memory should change, and the file doesn't always
end at the end of a record, I decided on using Getmem and Blockread.
My problem is this. I have code like the following:

Getmem(CurrentByte,1);
Getmem(Byteswaiting,BlockSize-1);
BlockRead(FileOnDisk,CurrentByte^,1);
BlockRead(FileOnDisk,BytesWaiting^,BlockSize-1,BytesRead);

which reads the first byte into Currentbyte^ and the rest of the
1K (or whatever) into Byteswaiting^. After the first byte is read,
the remaining bytes should shift left to put the first Byteswaiting
into Currentbyte. The only problem is that a dump of memory revealed
the following:

EC 2B 00 F7 66 F6 8B F8 F9 BB 98 CD 3E 12 55 FD
^^ ^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^...
| | |_____________________
CurrentByte^ | |
| |
Must be some sort |
of hardware thing. I assume BytesWaiting^
variables must be on an 8
byte boundary?

When I Move(BytesWaiting^,CurrentByte^,BlockSize-1) I get:

F9 BB 98 CD 3E 12 55 FD 39 21 9E FF 1D 9E 1D 2A

THen, the program reads the F9, then shifts again. The problem is
in those 7 bytes that are there for some reason unknown to me. When
I move Byteswaiting^ over to CurrentByte^, it moves, I read the first
byte (although 8 have moved). Then I move again, and I lose the 7
bytes sitting on that boundary. Does ANYONE have a solution for
my problem? (Or understand anything I just said?)

Millions of thanks in advance,

Tim
--
____/| ACK! fre...@dynahill.com
\`o.O'/ THPPT! ad...@detroit.freenet.org
==(___)== "Hard work beats talent, if talent doesn't work hard."
U

Lou Duchez

unread,
Dec 20, 1994, 5:48:14 AM12/20/94
to
> EC 2B 00 F7 66 F6 8B F8 F9 BB 98 CD 3E 12 55 FD
> ^^ ^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^...
> | | |_____________________
> CurrentByte^ | |
> | |
> Must be some sort |
> of hardware thing. I assume BytesWaiting^
> variables must be on an 8
> byte boundary?
>
> When I Move(BytesWaiting^,CurrentByte^,BlockSize-1) I get:
>
> F9 BB 98 CD 3E 12 55 FD 39 21 9E FF 1D 9E 1D 2A

Why move the memory? Repoint the pointer, I say!

CurrentByte^ := BytesWaiting^;
while (...) do begin
process_byte(CurrentByte^);
inc(CurrentByte);
end;

As for the boundary: I think there's some switch to turn on or off
that governs variable alignment. More I cannot say.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
When they took the fourth amendment, I was quiet because I don't deal drugs.
When they took the six amendment, I was quiet because I'm innocent.
When they took the second amendment, I was quiet because I'm don't own a gun.
Now they've taken the first amendment and I can't say anything at all.

DOYLE PATRICK

unread,
Dec 19, 1994, 1:30:59 PM12/19/94
to
In article <3d2kck$6...@detroit.freenet.org>,

Tim Fries <ad...@detroit.freenet.org> wrote:
>
>My problem is this. I have code like the following:
>
> Getmem(CurrentByte,1);
> Getmem(Byteswaiting,BlockSize-1);
> BlockRead(FileOnDisk,CurrentByte^,1);
> BlockRead(FileOnDisk,BytesWaiting^,BlockSize-1,BytesRead);
>

Try it this way:

type
BufferType = array [1..BlockSize] of byte;

var
BufferPtr : ^BufferType;

...then...

getmem (BufferPtr, BlockSize);
blockread (FileVar, BufferPtr^, BlockSize, BytesRead);


The first byte will always be at BufferPtr^[1]. Then you can shift it.
Alternatively, rather than shift a thousand bytes every time, just access
them sequentially, like BufferPtr^[2], [3], etc. Then, when you get to
so that the index = BytesRead, you need to do another blockread. (Unless
BytesRead < BlockSize)

Hope that helps. If you e-mail me, I think I can dig up a buffering unit
that might help.

-Pat


Duncan Murdoch

unread,
Dec 19, 1994, 2:41:00 PM12/19/94
to
In article <3d2kck$6...@detroit.freenet.org> ad...@detroit.freenet.org (Tim Fries) writes:

>I've got a question for anyone who can answer it.
>I'm updating a program that used to access a file on disk one byte at
>a time. I've been looking for ways to speed up the program and the
>frequency of disk accessing was my #1 concern. Anyway, instead of
>reading byte by byte as it's needed, I thought I could read some
>larger value, say 1K, into memory and use it from there, then read
>another 1K from disk when the 1K in memory is used.

Since your sample code was using Blockread, I assume you're using TP. As long
as you're using version 6 or later, you should just use a buffered stream to
read your data. Don't bother writing your own buffering code, Borland has
already done it for you. For example:

uses objects; { To get the stream code linked in }
var
S : TBufStream;
b : byte;
i : integer;
begin
S.init('somefile',stOpenRead,1024); { Open with a 1K buffer }
for i:=1 to 10000 do
begin
S.read(b,1); { Read a byte, either from the disk or the buffer; you
don't need to worry about which }

...
end;
S.done; { Close the file }
end.

It's really much easier to use streams than you'd guess from
reading the manual.

Duncan Murdoch

Malcolm Coulter

unread,
Dec 21, 1994, 4:35:57 AM12/21/94
to
In article <D12M3...@ecf.toronto.edu> doy...@ecf.toronto.edu (DOYLE PATRICK) writes:
>From: doy...@ecf.toronto.edu (DOYLE PATRICK)
>Subject: Re: HELP!
>Date: Mon, 19 Dec 1994 18:30:59 GMT

[omitted text]

> Try it this way:

>type
> BufferType = array [1..BlockSize] of byte;

---------------------------------------------------------
or BufferType = array [1..$FFF0] of byte;

if BlockSize has a run-time value.
---------------------------------------------------------

>var
> BufferPtr : ^BufferType;

>...then...

>getmem (BufferPtr, BlockSize);
>blockread (FileVar, BufferPtr^, BlockSize, BytesRead);


[omitted text]


0 new messages