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
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.
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
>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
[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]