The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
shared memory read/write using threads kumars High Level Programming 2 06-18-2008 03:01 PM
HP-UX Trying to Understand Shared Memory Segments scotbuff HP-UX 2 03-17-2008 05:05 PM
Shared memory in shared library DreamWarrior High Level Programming 12 05-30-2007 04:33 PM
Shared Memory segments catwomen HP-UX 2 02-28-2006 10:07 AM
Shared memory shortage but lots of unused memory cjcamaro UNIX for Advanced & Expert Users 1 10-13-2004 05:10 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-20-2008
mae4 mae4 is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 1
Write into shared memory segments

I have created a shared memory segment (which size is 64 bytes) using shmget, shmat e.t.c and i want to divide it into 2 areas. One area for input data and one area for output? How can i do that?

Furthermore, When i have to write my input data into the shared memory segment i want to write something like this:

a text messase, an integer, another integer

Which function of c should i use? If i had to write only a text message and read it from another process i would use memcpy, but now i have the text messase and two integers (which i use as flags in my code).
  #2 (permalink)  
Old 11-20-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,715
You can memcpy them - integers are stored in binary format, not as textual digits.
To read it back out, you have to know the exact format of what was written to start with.

IF you don't like that use sprintf() then memcpy();
  #3 (permalink)  
Old 11-20-2008
Corona688 Corona688 is offline
Registered User
  
 

Join Date: Aug 2005
Location: Saskatchewan
Posts: 1,928
Quote:
Originally Posted by mae4 View Post
I have created a shared memory segment (which size is 64 bytes) using shmget, shmat e.t.c and i want to divide it into 2 areas. One area for input data and one area for output? How can i do that?
I'm guessing the purpose of that is to make half of it read-only. If so, you should just make two segments, I don't think you can make half of a segment read-only and certainly not in tiny 32-byte chunks. The OS can only actually map and protect memory in chunks of size pagesize(), which is often 4 kilobytes or more. See mmap() and mprotect() for details on what it's doing.

If that's not what you mean then I don't understand your question. Why not just use the upper and lower halves as is?
  #4 (permalink)  
Old 11-25-2008
techlinux techlinux is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 86
mmap PROT_READ and PROT_WRITE I think would probably work for what you want to do
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:45 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0