Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Memory-mapped files  (Read 5205 times)

0 Members and 1 Guest are viewing this topic.

Tomis

  • Newbie
  • *
  • Posts: 3
    • View Profile
Memory-mapped files
« on: August 13, 2010, 12:05:05 am »
Hi there, I'm a SFML user and I was wondering if there will be some support for a cross-platform API for memory-mapped files. As you probably know this technique can help a lot when using a single monolithic file to hold all your application resources, there are many potential advantages, performance-wise.

I'm still new to memory-mapped files so maybe I'm missing something but I think that if it's feasible they are a must. I'll look more into it and let you know if I find anything else.

Thank you.

Spodi

  • Full Member
  • ***
  • Posts: 150
    • View Profile
    • http://www.netgore.com/
Memory-mapped files
« Reply #1 on: August 13, 2010, 12:57:17 am »
I'm not sure what benefits this would bring to the SFML-side of things. When you load content from files (such as images), the file is parsed then stored and handled internally in an internal format. So its not like if you load a JPEG, it just keeps that image in memory in the same JPEG format. This is why the format you use to store images on disk doesn't affect how it performs or the size in memory (except the time it takes to load).

Not saying memory-mapped files aren't useful, just don't see how it relates to SFML.

Tomis

  • Newbie
  • *
  • Posts: 3
    • View Profile
Memory-mapped files
« Reply #2 on: August 13, 2010, 09:50:47 am »
I think mmf are related to SFML because it provides a cross-platform API for various OS functions. It's not a question of loading content from files, it's a question of providing a more elegant kind of access to various resources in a monolithic file without having to load all the file into memory (or parse it from one end to another).

mmf functions aren't portable across Windows and Linux so I think such an API might be useful for SFML users.

P.S. - http://burningsmell.org/SDL_mmap/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Memory-mapped files
« Reply #3 on: August 13, 2010, 09:56:18 am »
Quote
I think mmf are related to SFML because it provides a cross-platform API for various OS functions

This is not the prupose of SFML. SFML provides functions related to multimedia; the provided OS functions are limited to the strict minimum (ie. what SFML needs internally).
But go ahead and implement sfml-mmap if you want ;)
Laurent Gomila - SFML developer

Spodi

  • Full Member
  • ***
  • Posts: 150
    • View Profile
    • http://www.netgore.com/
Memory-mapped files
« Reply #4 on: August 13, 2010, 11:13:32 am »
Quote from: "Tomis"
It's not a question of loading content from files, it's a question of providing a more elegant kind of access to various resources in a monolithic file without having to load all the file into memory (or parse it from one end to another).


Sounds like more what you want is better/different resource management from SFML, which probably would fall under the category of SFML. Though finding a way that suits everybody's needs while still implementing enough to be useful but not too much to be complex... that'd be pretty difficult.

Tomis

  • Newbie
  • *
  • Posts: 3
    • View Profile
Memory-mapped files
« Reply #5 on: August 13, 2010, 01:34:22 pm »
Quote from: "Laurent"
But go ahead and implement sfml-mmap if you want ;)

I just might, if there aren't viable cross-platform libs (I saw Boost has something like that, I'll try it out). It's a good thing that SFML is open source.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Memory-mapped files
« Reply #6 on: August 13, 2010, 01:42:22 pm »
Quote
It's a good thing that SFML is open source.

If what you mean is "I can modify it myself", you don't need to. You can plug your library to the LoadFromMemory functions.
Laurent Gomila - SFML developer

Spodi

  • Full Member
  • ***
  • Posts: 150
    • View Profile
    • http://www.netgore.com/
Memory-mapped files
« Reply #7 on: August 13, 2010, 07:38:01 pm »
I'll mention what I did for handling content since I was very, very pleased with the results.

Basically, what I wanted was a generic content manager that loads any type of content (sounds, graphics, fonts, etc) all on the fly on-demand, with the ability to stream it in the background for pre-fetching (nobody likes to wait). I also wanted to assign a "level" to each content, which included: Temporary, Map, Screen, and Global. These values stated when automated collection would take place. Temporary was always cleaned on collection, map was cleaned when changing maps (which also cleaned temporary), etc. Most importantly, if I tried using any content that was not loaded into memory, it had to auto-load into memory.

With SFML, this was insanely easy, and was my major motivation to change from XNA. With XNA, almost all of what I listed above was a nightmare since it had its own content management system that was very strongly locked-down. With SFML, all I had to change on the SFML side to accomplish this was the lazy loading. To do that, I just created my own derived classes that accept the filename at construction, then override the accessor to the internal reference pointer so that, if it was not loaded, it loads right then and there. If its loaded, continue on.

Very easy, but works beautifully. :)

WitchD0ctor

  • Full Member
  • ***
  • Posts: 100
    • View Profile
    • http://www.teleforce-blogspot.com
Memory-mapped files
« Reply #8 on: August 19, 2010, 06:48:30 am »
sounds like you want something like Physfs, which is something that can work well with SFML anyway, amiright?
John Carmack can Divide by zer0.