dynamic shared memory


 
Thread Tools Search this Thread
Top Forums Programming dynamic shared memory
# 1  
Old 04-09-2006
dynamic shared memory

Hi
I need help regarding shared memory. I need to maintain the following structure in shared memory.

struct linked_list_header{
pid_t pid;
pthread_mutex_t lock;
int top;
int end;
int free;
NODE *ptr
}
The node structure is as follows
struct NODE {
int index;
int prv;
int nxt;
void *buffer;
}
Is it possible to maintain this dynamic linked_list_header in shared memory. I tried to maintain the same BUT I am not able to share the NODE structre data among the processes.

Thanks a lot
axes
# 2  
Old 04-10-2006
If you called malloc to create linked_list_header->ptr, then the address returned by malloc is private to the calling (the process that calls malloc) process. Same with NODE->buffer. You will have to allocate these things in shared "by hand" without calling malloc.
# 3  
Old 04-11-2006
Thanks a Jim
I corrected my program to share the memory instead of malloc, Now it is working fine. I need another clarification regarding the same.

During run time, If I need more shared memory, Is it possible to mmap the increased size of dynamic memory while retaining the contents of previously mmaped memory. ( like realloc's functionality which preserves previously allocated memory contents)

Thanks once again
axes
# 4  
Old 04-11-2006
You mmap a second memory area. However mmap is not like malloc or realloc.
It works using pages of memory, not bytes. Create a really large memory block to start with. It sounds like you're using Linux.

Linux supports system V IPC XPG4.2 calls:

sys/shm.h provides support for shmat(), shmget(), etc.. You may also want to look at those calls.
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. Programming

Dynamic Memory Allocation

Hello Guys I have a small confusion in the dynamic memory allocation concept. If we declare a pointer say a char pointer, we need to allocate adequate memory space. char* str = (char*)malloc(20*sizeof(char)); str = "This is a string"; But this will also work. char* str = "This... (2 Replies)
Discussion started by: tene
2 Replies

3. Programming

Shared, Static , Dynamic?

if I could compile the same source file as shared/static/dynamic what are the advantages/ disadv of each. PS:by dynamic i am asking about usage of "dlopen". How is it particularly diff from shared libs (2 Replies)
Discussion started by: dragonpoint
2 Replies

4. UNIX for Dummies Questions & Answers

Problem with shared dynamic library files

I am having a major problem. Most of the commands that i am running on my centos 5 system is giving the error of type: <dynamic shared library file>:open failed: No such file or directory For example: libgcc_s.so.1: open failed: No such file or directory How can i solve this? (6 Replies)
Discussion started by: proactiveaditya
6 Replies

5. UNIX for Dummies Questions & Answers

How to obtain list of object files in a shared (dynamic) library?

How can I simply obtain a list of the object files in a shared (dynamic) library. I am looking for the equivalent of "ar -t <lib>" for archived (static) libraries. Thanks in advance. :rolleyes: ---------- Post updated at 01:47 PM ---------- Previous update was at 12:16 PM ---------- The... (1 Reply)
Discussion started by: chatieremerrill
1 Replies

6. 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

7. 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

8. Programming

memory sharing - not shared memory -

hi, this is the problem: i want to swap a linked list between 4 processes (unrelated), is there any way i can do that just by sending a pointer to a structure? //example typedef struct node { int x; char c; struct node *next; } node; or i should send the items ( x,c ) by... (9 Replies)
Discussion started by: elzalem
9 Replies

9. Linux

load dynamic and shared library in kernel

hi how can i load dynamic or shared library in linux kernel modules . mtaghiloo@yahoo.com (0 Replies)
Discussion started by: mtaghiloo
0 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