Author Topic: Reading a file into memory  (Read 10651 times)

frktons

  • Member
  • ***
  • Posts: 491
Re: Reading a file into memory
« Reply #15 on: January 19, 2013, 02:00:39 PM »
the example i posted has a function named SizFile that will get the full size
Yes Dave, good example.  :t

To speed things up for huge files, allocate buffers with VirtualAlloc to get them on page boundaries (4096) which is also a sector boundary for either 4096 BYTE sector size files or 4096 BYTE sector size, then use unbuffered reads.

Dave.

Hi Dave, I don't know much about this, if you can post an example it could be helpful.

KeepingRealBusy

  • Member
  • ***
  • Posts: 426
Re: Reading a file into memory
« Reply #16 on: January 19, 2013, 02:12:19 PM »
Here is a sample I sent to Yves last Sept.

Dave.

frktons

  • Member
  • ***
  • Posts: 491
Re: Reading a file into memory
« Reply #17 on: January 19, 2013, 02:19:55 PM »
Here is a sample I sent to Yves last Sept.

Dave.

Thanks Dave. I'll give it a shot and read the code and comments.

KeepingRealBusy

  • Member
  • ***
  • Posts: 426
Re: Reading a file into memory
« Reply #18 on: January 19, 2013, 02:22:28 PM »
You have to tie a lot of things together, but it works and saves time.

Dave.

frktons

  • Member
  • ***
  • Posts: 491
Re: Reading a file into memory
« Reply #19 on: January 19, 2013, 02:25:34 PM »
You have to tie a lot of things together, but it works and saves time.

Dave.

What it does? It is quite big.

KeepingRealBusy

  • Member
  • ***
  • Posts: 426
Re: Reading a file into memory
« Reply #20 on: January 20, 2013, 03:11:48 AM »
Well, you start at the beginning. The highest level directory has a makeit.bat file, and it says to assemble yves.asm. You look at that and find that it is only an include of \pkg\yves.pkg. You look at that and at the end of the file you find the end statement "end Main", so the program starts at Main. It also has another bunch of includes tying the whole package together. Go to Main and find that it calls Initialize, then Memory, then OpenAllFiles, then ReadTheFile, then  WriteTheFile, then finally calls Shutdown.

So basically, it is a file copy program, but uses unbuffered reads and writes to do the job, and VirtualAlloc to get the memory buffer.

If you execute makeit.bat, you will end up with a .lst file which contains all of the code in a single file, and it is easier to find your way around that instead of the individual files.

Note this is self contained, it does not use any external libraries except for the kernel32.lib to get the system APIs.

Dave.


KeepingRealBusy

  • Member
  • ***
  • Posts: 426
Re: Reading a file into memory
« Reply #21 on: January 20, 2013, 03:22:42 AM »
You have to tie a lot of things together, but it works and saves time.

Dave.

What it does? It is quite big.

OBTW, it is not "big", the .lst file is only 12,000 lines. When you get up to 100,000 lines, then you can start calling a program big.

Dave.

frktons

  • Member
  • ***
  • Posts: 491
Re: Reading a file into memory
« Reply #22 on: January 20, 2013, 04:50:39 AM »
Well, you start at the beginning. The highest level directory has a makeit.bat file, and it says to assemble yves.asm. You look at that and find that it is only an include of \pkg\yves.pkg. You look at that and at the end of the file you find the end statement "end Main", so the program starts at Main. It also has another bunch of includes tying the whole package together. Go to Main and find that it calls Initialize, then Memory, then OpenAllFiles, then ReadTheFile, then  WriteTheFile, then finally calls Shutdown.

So basically, it is a file copy program, but uses unbuffered reads and writes to do the job, and VirtualAlloc to get the memory buffer.

If you execute makeit.bat, you will end up with a .lst file which contains all of the code in a single file, and it is easier to find your way around that instead of the individual files.

Note this is self contained, it does not use any external libraries except for the kernel32.lib to get the system APIs.

Dave.

Thanks Dave, at least now I understand something more.
Usually a copy program calls a small quantity of APIs and
has 400-1000 instructions more to do things around the
main goal.
12,000 instructions are quite a lot for a simple copy file to
file. I imagine you put inside many more things.

By the way I've seen it is a console program, and it expects
2 file name as parameters.
If you can tell me what happens when I use: c:\whatever\pgm.exe file1.xxx file2xxx
or if there is another correct syntax, then I know also how to use it.

Thanks anyway for your patience.