Correct use of BlockRead or alternative loading approach 
Author Message
 Correct use of BlockRead or alternative loading approach

hokay, i'll start off, for those who want to get angry, that yes, this is
a problem resulting from my trying to use a procedure i didn't write and
don't fully understand ... sorry ... that out of the way, i found a
procedure to take care of a problem i've been having (won't get into it)
... it requires that a file be loaded into memory, with a pointer to the
data in memory ...
i haven't done that before, and i guessed that it might be accomplished
with the BlockRead procedure ...
anyway, i won't try to explain what i know about blockread (not much), cuz
i assume the person who answers this question will have used it before ...
i tried doing it with
blockread(filevar,var of type pointer, $1000, var of type word -- result);

i had hoped that this would load the first 16^3 * 128 bytes into memory,
make my pointer variable the pointer to the data, and make the result
variable hold the actual size of the data read ... unfortunately, result
held a zero ... not good ... then i tried making it $100, and it crashed
... (froze up, couldn't even c-a-d)

so anyway, having proven my ignorance, what can i do to load a file into
memory (we're talking 10's of KB) and end up with a pointer to the data
and the size of the data?  is blockread the right way and i'm just doing
it wrong, or am i completely off?

many thanks,
-dave

-----------------------------------------------------------------------------
Dave Caputo     | "If you want to know something he won't tell you, cut off

                | thumb is next.  After that he'll tell you if he wears
                | ladies' underwear." -- Mr. White
-----------------------------------------------------------------------------



Wed, 18 Jun 1902 08:00:00 GMT  
 Correct use of BlockRead or alternative loading approach

Quote:

> hokay, i'll start off, for those who want to get angry, that yes, this is
> a problem resulting from my trying to use a procedure i didn't write and
> don't fully understand ... sorry ... that out of the way, i found a
> procedure to take care of a problem i've been having (won't get into it)
> ... it requires that a file be loaded into memory, with a pointer to the
> data in memory ...
> i haven't done that before, and i guessed that it might be accomplished
> with the BlockRead procedure ...
> anyway, i won't try to explain what i know about blockread (not much), cuz
> i assume the person who answers this question will have used it before ...
> i tried doing it with
> blockread(filevar,var of type pointer, $1000, var of type word -- result);

> i had hoped that this would load the first 16^3 * 128 bytes into memory,
> make my pointer variable the pointer to the data, and make the result
> variable hold the actual size of the data read ... unfortunately, result
> held a zero ... not good ... then i tried making it $100, and it crashed
> ... (froze up, couldn't even c-a-d)

> so anyway, having proven my ignorance, what can i do to load a file into
> memory (we're talking 10's of KB) and end up with a pointer to the data
> and the size of the data?  is blockread the right way and i'm just doing
> it wrong, or am i completely off?

BlockRead is a good way to go if you want to load 10's of KB quickly.
I suspect the problem lies in other matters.  For starters, BP is still
essentially a real-mode compiler, ans so you can't load more than 64KB
at a time with BlockRead.  I dunno 'bout DPMI, but I'm pretty sure
there will be problems with > 64KB at a time with that anyway, due to
the use of real-mode DOS.

I don't recall the manual/help screen on this, but I don't think it was
very clear about the BlockRead call.  You have to give it the address
to store the data, rather than it loading the data and telling you
where it put it.

My guess is (it sounds like) you are not allocating the memory for
BlockRead to use.  BlockRead doesn't allocate any memory off the heap,
it only uses what you gave it.  If you haven't allocated the memory in
advance, it tries to load the block from the file to whatever random
memory address the (uninitialized) pointer happened to be pointing at
when you called BlockRead.... and chances are quite good that you
clobbered something *very* important (hence the freezing, no c-a-d).
What you need to do is call
   new(var_of_type_pointer_to_buffer);
or
   getmem(var_of_type_pointer,size_of_memory_block_in_bytes);

I'm not sure which variety is more appropriate in this application, but
I'm pretty sure that'll fix the problem.  

The size of the data should come back correctly if everything else went
ok.  There is a quirk involving block sizes;  I just used block size of
1 when opening the file and computed the number of bytes myself (but
then again, I was usually dealing with text files, so characters were
the natural unit to work in.)

HTH

Stephen Ryan    Team OS/2
Mathematics graduate student, Dartmouth College



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Approaches/alternatives to the ReportSmith nightmare?

2. blockread/write using file handles?

3. Saving time using inline assy to do blockread..

4. Using an alternative idapi.cfg file

5. Correct approach for summing field value of detail table in master/detail setup?

6. Help Me Please (S.O.S. pascal) -- load bmp images using pascal

7. WANTED: A Simple unit for loading 256 color bitmaps using TPW 1.5

8. using resource in Delphi - loading Jpg file into

9. using a dbedit field to load a picture in an image field

10. Saving and loading JPEG from Paradox7 table- Error on load

11. Speed versus size - the right approach ???

12. Lotus Approach DBF's are read only!!

 

 
Powered by phpBB® Forum Software