flat assembler
Message board for the users of flat assembler.

Index > Windows > Load a binary file to memory

Author
Thread Post new topic Reply to topic
sekigun



Joined: 23 Dec 2004
Posts: 18
Location: Japan
sekigun
I am writing a file compressor and I need to load a file(likely to be large >500 Mbs) to memory. Which is the fastest way to do this? Also if the file is that large would it be faster if I processed the file loading it in smaller bits instead of loading the full file and thus using the disk emulated memory?
Post 30 Jan 2005, 16:54
View user's profile Send private message Reply with quote
r22



Joined: 27 Dec 2004
Posts: 805
r22
The best way I can think of is file mapping...

xor ebx,ebx
push ebx
push 1FFFFFFFh ;size you want
push ebx ;high end of 64bit max size
push dword 4 ;page readwrite
push ebx
push dword 0FFFFFFFFh ;invalid handle
call [CreateFileMapping]
push ebx
push ebx
push ebx
push dword 0F001Fh ;SECTION_ALL_ACCESS
push eax
call [MapViewOfFile]
mov dword[baseAddr],eax

Now you can just open, read, write your file into the baseAddr, you can also filemap the file you want instead of passing an invalid handle pass the handle to the file.
Post 31 Jan 2005, 02:53
View user's profile Send private message AIM Address Yahoo Messenger Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
i quess windows won't really handle that, iff file is over ~3gb, because it has to allocate large chunk of virtual memory which it can't do (it can handle only 4 gigs at all). I suggest you hadnling file sequentially or writing your own routine that simulates memory reads you would do if file was loaded in memory.
Post 31 Jan 2005, 15:13
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
What kind of processing do you need to do?

If you need random access, file mapping is probably the best; you don't have to map the entire file at once (with very large files this is a bad thing to do anyway, especially on Win9x because of the shared address space).

If you process the file from start to end, it's probably better to use normal ReadFile and process the file in chunks - this uses less total memory, and avoids the need for other processes to have their working set trimmed.
Post 01 Feb 2005, 09:59
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.