Menu

#356 Speedup HDD or CD ISO emu using memory mapping

open
nobody
I/O device (66)
5
2012-10-15
2006-01-21
Anonymous
No

I don't know how the HDD and ISO CD images emulated in
Bochs but I assume they have to read/write huge files,
up to gigabytes of size.
I had experience with it past, I had huge file
containing polygons and had to read it them starting
from random place as fast as possible. Original
solution was keeping the polygons file open and
calling seek function before every read. It was just
SLOOOW.
Using memory map it is possible to speed up such kind
of operations 5x and more. The file is mapped to the
memory by OS and 'user' holds only a pointer to the
byte array (unsigned char*). When all the file
operations could be forgotten, you just work with
array like it is located in main memory and OS manage
all the operations in right way (read file to memory
when needed, switch pages and swap). And does it much
faster than regular file operations do.
I wonder if it is possible to apply memory mapping
approach to Bochs HDD or CD emulation. It even could
be done in multiplatform way, in UNIX we could use
mmap as is and in Windows write 'mmap emulator', the
function with the same params which using WIN32 API
methods. Or we could write some common MMAP interface
and implement it differently for UNIX and WINDOWS.
I attached my class CMemMapFile I wrote before, the
main interface of the class is only one function

LPCVOID CMemMapFile::OpenMapFile(const string
&filename)

It opens the file (read only), maps to the memory and
returns LPCVOID which is nothing more than (const
void*). When you could use the pointer like all the
file just loaded to the memory.

Stanislav

Discussion

  • Nobody/Anonymous

    CMemMapFile class implementation

     
  • Stanislav Shwartsman

    CMemMapFile class include

     
  • Stanislav Shwartsman

    Logged In: YES
    user_id=487634

    BTW, if you more familiar with mmap/munmap functions and
    want to use them for both UNIX and Win32:

    http://synesis.com.au/software/unixem.html

    Synesis Software released (under BSD) licence the UNIX
    syscalls emulation methods for Win32. Simple and could be
    compiled with any Win32-compatible compiler.

    Stanislav

     
  • ytre

    ytre - 2006-12-19

    Logged In: YES
    user_id=1065332
    Originator: NO

    not much use for 32bit host because of limited address space.
    flat mode may be realy lot faster with this

     

Log in to post a comment.