Jump to content
  • Advertisement
Sign in to follow this  
BradDaBug

Unity Cross platform memory mapping Part 2

This topic is 4977 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!