473,625 Members | 2,615 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

need to be able to write in a shared mem segment.

hi all,
i am running slackware linux and need to use some function that will
will enable me to write and read from a shared mem segment..
i am using open() , to open a file, and then use mmap to get a void*
file_memory pointer. then i use fwrite(aStruct, structSize,1,(( (FILE*)
file_memory) + anOffset)) to try to write to the file but it crashes.

could it be that fwrite does not understand the file_memory pointer?
what else can i use to do the writing?
thankyou for your help
nass

Sep 23 '06 #1
7 2826
nass wrote:
hi all,
[OT redacted]
You might try a group where your question can be better answered.

http://www.parashift.com/c++-faq-lit...t.html#faq-5.9
Sep 23 '06 #2
nass wrote :
hi all,
i am running slackware linux and need to use some function that will
will enable me to write and read from a shared mem segment..
You could use boost.interproc ess (used to be boost.shmem)
Sep 23 '06 #3
nass schrieb:
hi all,
i am running slackware linux and need to use some function that will
will enable me to write and read from a shared mem segment..
This is offtopic here, but...
i am using open() , to open a file, and then use mmap to get a void*
file_memory pointer. then i use fwrite(aStruct, structSize,1,(( (FILE*)
file_memory) + anOffset)) to try to write to the file but it crashes.
The fourth parameter of fwrite must be a _unchanged_ FILE*, that you got by
calling fopen. You can't cast any pointer to a FILE* and write to that like
a file.

And you don't need to. You said that, mmap returns a memory pointer as
void*. So simply use it, just like you would use memory from a malloc() call.
could it be that fwrite does not understand the file_memory pointer?
exactly.

--
Thomas
http://www.netmeister.org/news/learn2quote.html
Sep 23 '06 #4


Thomas J. Gritzan wrote:
nass schrieb:
hi all,
i am running slackware linux and need to use some function that will
will enable me to write and read from a shared mem segment..

This is offtopic here, but...
i am using open() , to open a file, and then use mmap to get a void*
file_memory pointer. then i use fwrite(aStruct, structSize,1,(( (FILE*)
file_memory) + anOffset)) to try to write to the file but it crashes.

The fourth parameter of fwrite must be a _unchanged_ FILE*, that you got by
calling fopen. You can't cast any pointer to a FILE* and write to that like
a file.

And you don't need to. You said that, mmap returns a memory pointer as
void*. So simply use it, just like you would use memory from a malloc() call.
nope i cant do that, the compiler gives me an error saying
error: invalid conversion from `void*' to `FILE*'
its gcc btw.. any other posibility?

could it be that fwrite does not understand the file_memory pointer?

exactly.

--
Thomas
http://www.netmeister.org/news/learn2quote.html

nass

Sep 24 '06 #5
nass wrote:
>
Thomas J. Gritzan wrote:
>nass schrieb:
>>hi all,
i am running slackware linux and need to use some function that will
will enable me to write and read from a shared mem segment..
This is offtopic here, but...
>>i am using open() , to open a file, and then use mmap to get a void*
file_memory pointer. then i use fwrite(aStruct, structSize,1,(( (FILE*)
file_memory ) + anOffset)) to try to write to the file but it crashes.
The fourth parameter of fwrite must be a _unchanged_ FILE*, that you got by
calling fopen. You can't cast any pointer to a FILE* and write to that like
a file.

And you don't need to. You said that, mmap returns a memory pointer as
void*. So simply use it, just like you would use memory from a malloc() call.
nope i cant do that, the compiler gives me an error saying
error: invalid conversion from `void*' to `FILE*'
its gcc btw.. any other posibility?
mmap returns a pointer to the shared memory.
You do not use a 'FILE *' to write to that memory.
After the mmap you read/update it like any other memory
buffer.

You'll get better support in these newsgroups:

comp.os.linux.d evelopment.apps
comp.os.linux.d evelopment.syst em

Larry
>
>>could it be that fwrite does not understand the file_memory pointer?
exactly.

--
Thomas
http://www.netmeister.org/news/learn2quote.html


nass
Sep 25 '06 #6
for some reason i can not 'open' these 2 sites u recommended from a
newsgroups reader..
anyhow, igues you are refering to doing buffer read-update with
sprintf()... i would like to use that function too but the problem is i
have a struct that i need to save in the buffer, and i do not now what
type to instruct the sprintf function to 'think' my struct is....
the struct is not always the same.. but it contains in8, uint8, int32,
floats, doubles and even strings.
how could i use sprintf in order to save this struct?
nass

Larry I Smith wrote:
nass wrote:

Thomas J. Gritzan wrote:
nass schrieb:
hi all,
i am running slackware linux and need to use some function that will
will enable me to write and read from a shared mem segment..
This is offtopic here, but...

i am using open() , to open a file, and then use mmap to get a void*
file_memory pointer. then i use fwrite(aStruct, structSize,1,(( (FILE*)
file_memory) + anOffset)) to try to write to the file but it crashes.
The fourth parameter of fwrite must be a _unchanged_ FILE*, that you got by
calling fopen. You can't cast any pointer to a FILE* and write to that like
a file.

And you don't need to. You said that, mmap returns a memory pointer as
void*. So simply use it, just like you would use memory from a malloc() call.
nope i cant do that, the compiler gives me an error saying
error: invalid conversion from `void*' to `FILE*'
its gcc btw.. any other posibility?

mmap returns a pointer to the shared memory.
You do not use a 'FILE *' to write to that memory.
After the mmap you read/update it like any other memory
buffer.

You'll get better support in these newsgroups:

comp.os.linux.d evelopment.apps
comp.os.linux.d evelopment.syst em

Larry
>could it be that fwrite does not understand the file_memory pointer?
exactly.

--
Thomas
http://www.netmeister.org/news/learn2quote.html

nass
Sep 25 '06 #7
nass wrote:
for some reason i can not 'open' these 2 sites u recommended from a
newsgroups reader..
anyhow, igues you are refering to doing buffer read-update with
sprintf()... i would like to use that function too but the problem is i
have a struct that i need to save in the buffer, and i do not now what
type to instruct the sprintf function to 'think' my struct is....
the struct is not always the same.. but it contains in8, uint8, int32,
floats, doubles and even strings.
how could i use sprintf in order to save this struct?
nass

Larry I Smith wrote:
>nass wrote:
>>>

Thomas J. Gritzan wrote:
nass schrieb:
hi all,
i am running slackware linux and need to use some function that will
will enable me to write and read from a shared mem segment..
This is offtopic here, but...

i am using open() , to open a file, and then use mmap to get a void*
file_memo ry pointer. then i use fwrite(aStruct, structSize,1,(( (FILE*)
file_memory ) + anOffset)) to try to write to the file but it crashes.
The fourth parameter of fwrite must be a _unchanged_ FILE*, that you got by
calling fopen. You can't cast any pointer to a FILE* and write to that like
a file.

And you don't need to. You said that, mmap returns a memory pointer as
void*. So simply use it, just like you would use memory from a malloc() call.

nope i cant do that, the compiler gives me an error saying
error: invalid conversion from `void*' to `FILE*'
its gcc btw.. any other posibility?
mmap returns a pointer to the shared memory.
You do not use a 'FILE *' to write to that memory.
After the mmap you read/update it like any other memory
buffer.

You'll get better support in these newsgroups:

comp.os.linux.d evelopment.apps
comp.os.linux.d evelopment.syst em

Larry
>>>>could it be that fwrite does not understand the file_memory pointer?
exactly.

--
Thomas
http://www.netmeister.org/news/learn2quote.html

nass
Please do not top post.

One more time...

FORGET ABOUT 'FILE *'.

Once a file is mapped into memory - it's just memory.

The sprintf() example was just an example of one (of many)
ways to access the memory.

If you want to put a 'struct stuff' in the mapped memory,
just do it:

struct stuff * pStuff;

/* assuming that 'pMem' is the pointer returned by
* mmap() -AND- that the mapped memory is large
* enough to hold a 'struct stuff', this next line
* allows your code to treat the memory at 'pMem'
* as a 'struct stuff' - via 'pStuff'.
* anything put into '*pStuff' will be visible to
* all processes that have the same memory mapped.
*/
pStuff = (struct stuff *) pMem;

/* now write and read the members of the
* 'struct stuff' that resides at the beginning
* of the mapped memory, eg:
*/
pStuff->some_int_fie ld = 55;
This is NOT a C++ language issue so - Post to a
unix/linux newsgroup in the future.

READ THE DOCS ON THE MEMORY MAPPING FUNCTIONS.
It's all explained therein.

Larry
Sep 26 '06 #8

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

Similar topics

5
4397
by: Confused User | last post by:
I am working on device that utilizes a Motorola 68HC16 microcontroller. I am using an old unsupported piece of crap Whitesmith's / Intermetrics / Tasking compiler. The embedded compiler business was quite insestual for while wasn't it? I need to write putchar so that printf can function properly. Anyway, the compiler comes with just a shell of a putchar routine. It literally returns the character you passed to it and nothing else. That is...
4
2308
by: Zachary Hilbun | last post by:
I need to write an ASP that requires a user to give a User Name and Password to run it. Whenever I've used this on the Web it displays a standard dialog and then offers to save the User Name and Password on my computer so that I don't have to enter it again. How is it that this standard dialog is displayed? Does the ASP (in my case C#) do this or does the Web Server do this and the ASP never knows about it? ...
2
1409
by: Just Me | last post by:
Need to write a program that wakes up every 15 minutes and does something. I guess I could just create a Windows application and schedule it to run every 15 minutes. Or I could have a program always in memory that uses a timer to activate it every 15 minutes. 1) Any suggestions?
0
1191
by: jens Jensen | last post by:
Hello, I need to write a webservice that will authenticate via x509. The problem here is , i will configure it not to use SOAP. Just use http post. How can i add x509 authentication? Many thanks in advance
29
2140
by: jens Jensen | last post by:
Hello, I got this "breath taking" task to write a an http server to which "xml data" will be posted to and will answer with xml data. The logic behind the xml processing is not a matter here. My question is : Can i configure a webservice for HHTP POST ? The remote peer just performs an http web request. NO RPC style call to my system.
13
21692
by: Pradeep Vasudevan | last post by:
hai i am a student and need to write a simple web crawler using python and need some guidance of how to start.. i need to crawl web pages using BFS and also DFS... one using stacks and other using queues... i will try on the obsolete web pages only and so tht i can learn of how to do that.. i have taken a course called search engines and need some help in doing that... help in any knind would be appreciated.. thank u
2
2586
kamill
by: kamill | last post by:
i need to write content of one text file into another text file. My code is working ,if i choose both files from same directory where my program reside..BUT,its not working if i select files from out of that directory(where my application reside). how can i overcome to it. my code is this.. Form to select two files <form method="post" action="" enctype="multipart/form-data">
8
1486
seshu
by: seshu | last post by:
hi every body This is seshu, here iam able write a code in vb6 on controle arrays ofcourse while designing it self i made my controls as arrays but here in .net i dint find that option see the code in vb6 is like this Dim cont For Each cont In form If TypeName(cont) = "TextBox" Then cont.Text = "" Next and the code in vb.net is like this
0
8182
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,...
0
8688
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8635
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8494
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
7178
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...
0
5570
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
4085
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...
1
2614
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1496
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.