flat assembler
Message board for the users of flat assembler.

Index > Windows > MapViewOfFile vs ReadFile

Author
Thread Post new topic Reply to topic
a115433



Joined: 05 Mar 2010
Posts: 144
a115433 08 Apr 2010, 12:05
what io method is the best?
i belive that MapViewOfFile() because its more hardware related.
And it doesnt require RAM for buffer, i can just work on it as it was memory.
Maybe its slower if i do heavy work on file (instead of memory it use mapped hardware), but if for example im sending a file via network - there is no need for RAM buffer.
Post 08 Apr 2010, 12:05
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20454
Location: In your JS exploiting you and your system
revolution 08 Apr 2010, 12:07
"Best" in what way?

What are your goals? What are your requirements? It all depends upon what you are doing.
Post 08 Apr 2010, 12:07
View user's profile Send private message Visit poster's website Reply with quote
a115433



Joined: 05 Mar 2010
Posts: 144
a115433 08 Apr 2010, 13:35
send file over network
Post 08 Apr 2010, 13:35
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 08 Apr 2010, 15:13
Post 08 Apr 2010, 15:13
View user's profile Send private message Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3175
Location: Denmark
f0dder 08 Apr 2010, 15:23
When dealing with files, memory is used. When mapping a hardware device into memory space things are different, but this isn't really something you do with CreateFileMapping+friends.

There's - possibly - slightly more overhead when dealing with memory-mapped files than normal Read/WriteFile calls, since you'll get a pagefault (including ring3->ring0->ring3) for every 4kb accessed. Probably not something you'll be able to seriously benchmark unless you get hold of a really old CPU, though Smile
Post 08 Apr 2010, 15:23
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20454
Location: In your JS exploiting you and your system
revolution 08 Apr 2010, 15:38
a115433 wrote:
send file over network
Be more specific. What sort of network? 10Gb Ethernet or 1Mb Internet (it makes a big difference)? "Best" in what way? Less work for you to code? Less work for the OS to do? Less CPU overhead? Most network speed? Least SDRAM used? What?
Post 08 Apr 2010, 15:38
View user's profile Send private message Visit poster's website Reply with quote
a115433



Joined: 05 Mar 2010
Posts: 144
a115433 08 Apr 2010, 16:13
Quote:
since you'll get a pagefault

please more info about it.
in paging table memory mapped device has propably supervisor access bit set to 0, meaning that ring3 can access this memory. Its OS thing to allow or disallow ring3 access to memory, why would it restrict it to cpl < 3 when i havepermission to create mapping handle? Where do i have page fault?
I doubt that OS will swap out memory wich is used for memory mapped device, it must keep track of it.
Im not sure how it works, its my theory about it.

Quote:
"Best" in what way?

fast, simple, better, and without pointless resource waste.
Post 08 Apr 2010, 16:13
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20454
Location: In your JS exploiting you and your system
revolution 08 Apr 2010, 16:16
a115433 wrote:
fast, simple, better, and without pointless resource waste.
You can't have all together, not possible.
Post 08 Apr 2010, 16:16
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 08 Apr 2010, 16:27
TransmitFile seems to provide all that (although I'm not sure about the "pointless resource waste")
Post 08 Apr 2010, 16:27
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20454
Location: In your JS exploiting you and your system
revolution 08 Apr 2010, 16:44
Is TransmitFile actually "simple"? I imagine the OS has a lot of work to do internally. The OP has not stated what is meant by "best" or "better" so how can we know what is wanted?
Post 08 Apr 2010, 16:44
View user's profile Send private message Visit poster's website Reply with quote
a115433



Joined: 05 Mar 2010
Posts: 144
a115433 08 Apr 2010, 17:07
forget about TransmitFile, what are the flaws of memory mapped io?
Post 08 Apr 2010, 17:07
View user's profile Send private message Reply with quote
peter



Joined: 09 May 2006
Posts: 63
peter 26 Apr 2010, 02:43
Four years ago, I tested memory-mapped files (MMF) vs. ReadFile for large files on HDD under Win XP. The results: for uncached data (first-time read), the speed was similar, but if you read the same file again, MMF will be ­≈2 times faster, because it does not have to copy the memory, just remap the memory pages from cache. MMF is harder to use: there are more functions to call, and you cannot grow a file once it's created.
Post 26 Apr 2010, 02:43
View user's profile Send private message Visit poster's website Reply with quote
a115433



Joined: 05 Mar 2010
Posts: 144
a115433 26 Apr 2010, 07:06
ok how does mmf work?
does it instruct OS to map portion of HDD space to address space?
or is it something else, like creating page with no access, upon access calling page fault handler, redirecting to normal page, comparing 8 bytes, and using WriteFile/ReadFile to actually write data there?
Post 26 Apr 2010, 07:06
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 26 Apr 2010, 07:47
a115433,

CPU usually can't directly address HDD space (PIO/DMA vs. memory-mapped I/O). x86 OS usually uses demand-paging to achieve mapping effect. WriteFile/ReadFile use cache manager which, in turn, uses memory manager to map sections of file into system virtual address space.
Post 26 Apr 2010, 07:47
View user's profile Send private message 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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.