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 7 2804
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.interprocess (used to be boost.shmem)
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
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
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.development.apps
comp.os.linux.development.system
Larry
>
>>could it be that fwrite does not understand the file_memory pointer?
exactly.
-- Thomas http://www.netmeister.org/news/learn2quote.html
nass
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.development.apps
comp.os.linux.development.system
Larry
>could it be that fwrite does not understand the file_memory pointer?
exactly.
--
Thomas http://www.netmeister.org/news/learn2quote.html
nass
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_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.development.apps comp.os.linux.development.system
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_field = 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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?
...
|
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.
...
|
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...
|
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...
|
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...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
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...
| |