473,789 Members | 2,634 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 11181

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************ *********@f14g2 000cwb.googlegr oups.com>,
Divick <di************ @gmail.com> writes
Is there a way in C++ to have a file stream which is directly mapped to
memory(virtu al 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 MemoryMappedFil e 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
3086
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 mmapfile. Any example or link to an example will be of help. I am interested to learn how to achieve efficient sharing of data between separate processes using mmapfile.
1
1566
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
11954
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# using memory mapped file. We already have C++ code for handling memory mapped file. I am working on converting code for memory mapped file in C#. Now I have to pass pointer to the above structure. I converted this structure to C# as follows:
0
1886
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 have multiple threads which all map mmf, is there anyway to "lock" mmf to prevent simultanous writes? I don't know if it is wise to use mmf in .Net application, but I haven't found anything so smooth&quick way to change data between assemblies. ...
3
2358
by: nkrisraj | last post by:
Hi, I have a following structure: typedef struct { RateData rdr; int RateID; char RateBalance; } RateInfo;
8
3022
by: nkrisraj | last post by:
Hi, I have a following structure: typedef struct { RateData rdr; int RateID; char RateBalance; } RateInfo;
3
7559
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 iterator as following char *str = return_a_big_size_str(); istringstream ss(string(str), istringstream::in); istreambuf_iterator<char> bit(ss), eit; parsing(bit, eit);
1
2176
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 whatever part of it i'm working on? basically, i'm wondering if it would be ok for me to have multiple mmap's open on very large files as i read or write from them.
1
3487
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 any type with size) & be able to share data between multiple processes. Please Note: There will one process in C# which will be producing, the other consuming process will be implemented in C. And it is going to be vice-versa too, i.e., C process...
0
9663
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9511
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10136
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9979
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9016
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7525
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6765
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5415
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2906
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.