473,383 Members | 1,874 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

memory mapped file stream

Is there a way in C++ to have a file stream which is directly mapped to
memory(virtual memory) without actually having to create a file and
then memory mapping that file using system dependent calls?

I need this because I don't want to create a regular file on disk
(reasons for which are many , say directory permissions ), but being a
file pointer, someone can use that pointer as a regular file descriptor
for reading and writing.

Thanks,
Divick

Jan 19 '06 #1
6 11117

Divick wrote:
Is there a way in C++ to have a file stream which is directly mapped to
memory(virtual memory) without actually having to create a file and
then memory mapping that file using system dependent calls?
C++ does not provide such facilities. Platforms do.
I need this because I don't want to create a regular file on disk
(reasons for which are many , say directory permissions ), but being a
file pointer, someone can use that pointer as a regular file descriptor
for reading and writing. From words "file descriptor" I gather you are using some Unix-like OS.

Use mmap() to map memory not backed by a file.

http://www.opengroup.org/onlinepubs/...ions/mmap.html

Jan 19 '06 #2
In message <11*********************@f14g2000cwb.googlegroups. com>,
Divick <di************@gmail.com> writes
Is there a way in C++ to have a file stream which is directly mapped to
memory(virtual memory) without actually having to create a file and
then memory mapping that file using system dependent calls?

I need this because I don't want to create a regular file on disk
(reasons for which are many , say directory permissions ), but being a
file pointer, someone can use that pointer as a regular file descriptor
for reading and writing.

If you're not actually concerned with memory mapping, but just want an
object that can be read and written via operators >> and << without
being tied to a physical file, you might consider using a stringstream.

--
Richard Herring
Jan 19 '06 #3
>>If you're not actually concerned with memory mapping, but just want an
object that can be read and written via operators >> and << without
being tied to a physical file, you might consider using a stringstream.


My concern is not operators but a library which requires a file stream
for reading and writing. Since it is a C library, I am pretty sure that
it is not using << and >> operators for reading and writing. I assume
that it uses fread and fwrite calls for reading and writing.

Also although I am writing code on Linux but I also want the same code
to run on windows with minimal changes on windows as well, hence mmap
is not suitable for me as it can map a file to stream but I don't want
at all to create a regular file, apart from mmap being system dependent
call.

I can across common cpp library on gnu, which is cross platform (*nix
and windows only) which provides a portable MappedFile class using
which one can map, unmap and sync mapped files. But again it creates a
files which is what I don't want. Also just to have a mapped file, I
don't want to link with a totally new library.

Divick

Jan 19 '06 #4

Divick wrote:
If you're not actually concerned with memory mapping, but just want an
object that can be read and written via operators >> and << without
being tied to a physical file, you might consider using a stringstream.


My concern is not operators but a library which requires a file stream
for reading and writing. Since it is a C library, I am pretty sure that
it is not using << and >> operators for reading and writing. I assume
that it uses fread and fwrite calls for reading and writing.

Also although I am writing code on Linux but I also want the same code
to run on windows with minimal changes on windows as well, hence mmap
is not suitable for me as it can map a file to stream but I don't want
at all to create a regular file, apart from mmap being system dependent
call.

I can across common cpp library on gnu, which is cross platform (*nix
and windows only) which provides a portable MappedFile class using
which one can map, unmap and sync mapped files. But again it creates a
files which is what I don't want. Also just to have a mapped file, I
don't want to link with a totally new library.

Divick


Why not use TCP/IP (sockets) then?

Stephan

Jan 19 '06 #5
That would be like killing a fly by a sword.

Divick

Jan 21 '06 #6
On 19 Jan 2006 09:39:38 -0800, "Divick" <di************@gmail.com>
wrote:
I can across common cpp library on gnu, which is cross platform (*nix
and windows only) which provides a portable MappedFile class using
which one can map, unmap and sync mapped files. But again it creates a
files which is what I don't want. Also just to have a mapped file, I
don't want to link with a totally new library.


Then write your ovn MemoryMappedFile class.
You will have one header and at least two cpp files. In one you will
implement class with unix functions and in another with windows API
functions for that.

That's what I did. It was couple of days worth spending.
Darko
Feb 1 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Srijit Kumar Bhadra | last post by:
Hello, I see that it is possible to use mmapfile.pyd of win32all. The same is mentioned in http://www.python.org/windows/win32/#mmapfile. Unfortunately I could not trace any example using...
1
by: Jan | last post by:
Hi, I don't seem to find any c# methods for memory mapped file. Does C# have any? Or it is using different name? Thanks. Jan
2
by: vikas | last post by:
I have following structure in c++. typedef struct MMF_result_struct { int action; char text; int cols,rows; int month,day,year; } MMF_result; Now this structure is shared between C++ and C#...
0
by: Ville Pirhonen | last post by:
Hi ! I'm doing application with memory mapped file handling. I use mmf to change data between applications. Is dllimport the only way to use those mmf functions in VB.Net? In the application I...
3
by: nkrisraj | last post by:
Hi, I have a following structure: typedef struct { RateData rdr; int RateID; char RateBalance; } RateInfo;
8
by: nkrisraj | last post by:
Hi, I have a following structure: typedef struct { RateData rdr; int RateID; char RateBalance; } RateInfo;
3
by: wakun | last post by:
Hi there, I am seeking a fastest way to load a BIG string and parse it as a given format. I have a extern function which return a (char *)string in BIG size. Now, I am going to parse it with a...
1
by: Carl Mackey | last post by:
hi, i'm new to this list and new to python as well. i have a question on the memory mapped file ability python has. when i use a mmap on a file, will it copy the whole thing to ram or just...
1
by: manjuk | last post by:
Hi there, I have couple of questions. 1) Are Shared Memory & Memory Mapped Files same? 2) Is there a library/code that implements either of them? With which I can just pass object reference (of...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.