News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Reading a file into memory

Started by frktons, January 18, 2013, 07:30:40 PM

Previous topic - Next topic

frktons

Quote from: dedndave on January 19, 2013, 01:54:16 PM
the example i posted has a function named SizFile that will get the full size
Yes Dave, good example.  :t

Quote from: KeepingRealBusy on January 19, 2013, 01:57:52 PM
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.
There are only two days a year when you can't do anything: one is called yesterday, the other is called tomorrow, so today is the right day to love, believe, do and, above all, live.

Dalai Lama

KeepingRealBusy

Here is a sample I sent to Yves last Sept.

Dave.

frktons

Quote from: KeepingRealBusy on January 19, 2013, 02:12:19 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.
There are only two days a year when you can't do anything: one is called yesterday, the other is called tomorrow, so today is the right day to love, believe, do and, above all, live.

Dalai Lama

KeepingRealBusy

You have to tie a lot of things together, but it works and saves time.

Dave.

frktons

Quote from: KeepingRealBusy on January 19, 2013, 02:22:28 PM
You have to tie a lot of things together, but it works and saves time.

Dave.

What it does? It is quite big.
There are only two days a year when you can't do anything: one is called yesterday, the other is called tomorrow, so today is the right day to love, believe, do and, above all, live.

Dalai Lama

KeepingRealBusy

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

Quote from: frktons on January 19, 2013, 02:25:34 PM
Quote from: KeepingRealBusy on January 19, 2013, 02:22:28 PM
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

Quote from: KeepingRealBusy 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.

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.
There are only two days a year when you can't do anything: one is called yesterday, the other is called tomorrow, so today is the right day to love, believe, do and, above all, live.

Dalai Lama