Sign in to follow this  
BradDaBug

Unity Cross platform memory mapping Part 2

Recommended Posts

Back in this thread (which I would be replying to instead of creating a new topic but that thread's retired) I asked if there was a cross platform memory mapping library and someone posted some handy code to implement mmap() in Windows. The thing is that code requires an integer file descriptor, which I can't figure out how to get. If I wanted to use the *nix function open() to open the file I could, but I can't since this must also work in Windows. Is there a way to get a file descriptor from either a stdio FILE or a fstream object? Or will I still have to resort to a bunch of #ifdef's to use open() when compiling on *nix and some other Win32 function on Windows?

Share this post


Link to post
Share on other sites
hmm, the point of the mmap() wrapper is portability, right? You want to use the same POSIX routines in your main code, and let the emulation code do gyrations behind the scenes.
So why not emulate open() on Windows, just as with mmap()? All you have to do is call _open; depending on what you need to open, you can special-case /dev/tty and aio.


Anon Mike: ah, thanks! Didn't know fileno was portable, I always thought it (in the form of _fileno) was MS-specific. SUSv3 set me straight :)
Stdio-file handling + mmap is indeed possible.

Share this post


Link to post
Share on other sites
I discovered yesterday that Microsoft provides _open(), _close(), _read(), just about all the POSIX stuff I'd need. I just used some #define's to convert open() to _open(), etc. I haven't had a chance to test everything yet, but it compiles (I did all that before I heard about fileno(). Oh well.).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this