Write into shared memory segments


 
Thread Tools Search this Thread
Top Forums Programming Write into shared memory segments
# 1  
Old 11-20-2008
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  
Old 11-20-2008
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  
Old 11-20-2008
Quote:
Originally Posted by mae4
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  
Old 11-25-2008
mmap PROT_READ and PROT_WRITE I think would probably work for what you want to do
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Shared library with acces to shared memory.

Hello. I am new to this forum and I would like to ask for advice about low level POSIX programming. I have to implement a POSIX compliant C shared library. A file will have some variables and the shared library will have some functions which need those variables. There is one special... (5 Replies)
Discussion started by: iamjag
5 Replies

2. UNIX for Dummies Questions & Answers

Write/Read in Shared memory

I have created and attached a shared memory segment. However I do not know how am I supposed to write and read data from it. I want to save various different data on this segment such as process IDs and other. Do you know how am I supposed to write these and be able to read such data in the correct... (1 Reply)
Discussion started by: tyron
1 Replies

3. Programming

Urgent!!!! - Write/read to/from shared memory

I created a shared memory and attached it. I also created the appropriate semaphores to sync. my read/write operations. However I do not know how am I supposed to do so. Anyone has got any ideas? I want to write int the form of 1234:23:444:... where each number between : means something to the... (0 Replies)
Discussion started by: tyron
0 Replies

4. Programming

C programming - Memory Segments

Can someone tell me how many bytes are allocated for C segments(text,data,heap,stack). (3 Replies)
Discussion started by: nandumishra
3 Replies

5. Programming

Shared memory for shared library

I am writing a shared library in Linux (but compatible with other UNIXes) and I want to allow multiple instances to share a piece of memory -- 1 byte is enough. What's the "best" way to do this? I want to optimize for speed and portability. Obviously, I'll have to worry about mutual exclusion. (0 Replies)
Discussion started by: otheus
0 Replies

6. Programming

shared memory read/write using threads

I am looking for C program source code. Could you please help me in finding the source code required mentioned below. program to create multiple threads (one master thread and rest worker threads) and using the threads write into and read from shared memory Restrictions: Only one thread... (2 Replies)
Discussion started by: kumars
2 Replies

7. HP-UX

HP-UX Trying to Understand Shared Memory Segments

I am fairly new to HP-UX and trying to get a better understanding of the operating system. While poking around a bit I find myself questioning whether I should be concerned about Shared Memory segments with missing CPID and LPID? For example: ipcs -mp IPC status from /dev/kmem as of Mon Mar... (2 Replies)
Discussion started by: scotbuff
2 Replies

8. Programming

Shared memory in shared library

I need to create a shared library to access an in memory DB. The DB is not huge, but big enough to make it cumbersome to carry around in every single process using the shared library. Luckily, it is pretty static information, so I don't need to worry much about synchronizing the data between... (12 Replies)
Discussion started by: DreamWarrior
12 Replies

9. HP-UX

Shared Memory segments

Hello.... AIX has a limit of 11 shared memory segments per process, does any one know how many HP have?? If so how do I find that out?? Thanks in advance...... (2 Replies)
Discussion started by: catwomen
2 Replies

10. UNIX for Advanced & Expert Users

Shared memory shortage but lots of unused memory

I am running HP-UX B.11.11. I'm increasing a parameter for a database engine so that it uses more memory to buffer the disk drive (to speed up performance). I have over 5GB of memory not being used. But when I try to start the DB with the increased buffer parameter I get told. "Not... (1 Reply)
Discussion started by: cjcamaro
1 Replies
Login or Register to Ask a Question