4

What I want is simple to open file for reading as memory mapped file - in order to access it with much more speed in future (example: we open file read it to end, wait and read it again and again) Meanwhile I want that file to be modifiable by other programms and when thay modify it I want my ifstream to modify too. How to do such thing with boost iostreams (or boost interprocess)? Can we just tall os - hey this file shall be memory mapped for all apps?

So I try such code:

#include <iostream> 
#include <boost/iostreams/device/mapped_file.hpp> 
#include <boost/iostreams/stream.hpp> 

using namespace boost::iostreams; 

int main(int argc, char **argv) 
{
    stream <mapped_file_sink> out; 
    try 
    { 

        mapped_file_params p("one.txt"); 
        p.new_file_size = 1024 * sizeof (char); 
        out.open(mapped_file_sink(p),  std::ios_base::out | std::ios_base::binary); 
    } 
    catch (const std::exception &e) 
    { 
        std::cout << e.what() << std::endl; 
        return 2; 
    } 
    std::cin.get();
    return 0; 
} 

so it opens or creates file, puts it into ram. But I can not access it (I cant edit and save but I can open) from any other programm=( How to make file editable from other programms?

Rella
  • 65,003
  • 109
  • 363
  • 636
  • 1
    It is not clear what you want to do and what you have tried. For example, what do you mean when you say "I cant edit and save"? Are you trying to use an editor (which one?) and getting an error (which one? and when?) Please describe precisely: (1) your actions (2) results you are getting and (3) results you are trying to get. – n. m. could be an AI Aug 22 '11 at 05:52

1 Answers1

1

I guess that you're looking for file access speed but why reinventing the wheel? Use a memory mapped partition and create your files inside it. Then you just need to synch them into a disk partition from time to time so you don't lose info in case of a power failure... you can always invest on a UPS... ;-)

Pedro Ferreira
  • 852
  • 9
  • 23