Hi all,
I tried this.
struct check {
int data;
} *strucSup;
shmid =
shmget(key, 32768 * sizeof(strucSup), IPC_CREAT | 0666)) < 0);
This was working and the value inserted in one process was seen in other
process.
But when i tried this.
struct check {
int *data;
Where data is integer array.. Dynamically we need to allocate so that we can
store data.
} *strucSup
I tried to shmget for each data pointer but this is not good idea since it
creates a lot of small Shared memory. and we need to have the key for calling
all the data.
for (i = 0; i < MAX_IDXFILE; i++) {
testshm[i].data2 = shmget(i, 5 * sizeof(int), IPC_CREAT | 0666)) <
0);
testshm[i].data2 = shmat(shmid, NULL, 0)) == (int *)
-1);
for (j = 0; j < 5; j++) {
strucSup[i].data[j]
= j;
}
}
I think this is not good idea since it can lead
to segmentFault.
My question is:
1. Is that we need to create our own library function to fix this, which takes
chunk of shared memory and
allocates space in that memory region got from the shmget.
2. Is there any apache api which supports similar task.
Please let me know with your ideas.
Thanks in advance,
Jaysingh.
> From: [EMAIL PROTECTED]
> To: [email protected]
> CC: [EMAIL PROTECTED]
> Subject: RE: Load memory dyanamically using handler.
> Date: Thu, 11 Dec 2008 13:16:48 +0530
>
>
> Thanks for your input.
>
> Here is my problem i have 100's
> of files in different directories. and we store these files. ie the
> files in an Array and further hash table. Every time we do graceful the
> server to refresh the contents and that's why i need to
> dynamically reload the memory using some handlers .
>
> I need to dynamic create space for these structure and store the hash entries
> and datas.
> typedef struct abc{
> hash_t *table;
> } gInfoDB;
>
> typedef struct xyz{
> gInfoDB *ctDB;
> } InfoDB;
>
> InfoDB[10000];
>
> The
> server memory will have some max 10000 of InfoDB array in which the
> ctDB is malloced dynamically and store the contents of the files in
> the hash table.
>
> My question is:
>
> 1.The shared memory
> with which we get a chunk of memory. Can we further malloc and store
> the data's given by the shared memory. or we need to create keys and
> shared memory for every arrays.
> I have tried for arrays of structure and its works fine. But i was not able
> to do this.
>
> struct check {
> int *datum;
> } *strucSup;
>
> Here i was trying to malloc the datum and was able to store the data but
> getting segFault when tring through some other process. I can use further
> shmget the datum pointer but i don't want to do because this may create so
> many shared memory in my systems.
>
> Is there any work around to do this.
> Please guide me with the coding if you get.
>
> Thanks in advance,
> Jaysingh.
>
>
> > Date: Wed, 10 Dec 2008 09:09:19 +0100
> > From: [EMAIL PROTECTED]
> > To: [email protected]
> > Subject: Re: Load memory dyanamically using handler.
> > CC: [EMAIL PROTECTED]
> >
> > On Wed, Dec 10, 2008 at 06:00, Jayasingh Samuel
> > <[EMAIL PROTECTED]> wrote:
> > >
> > >
> > > I have 100's of files stored in different directories and i load all
> > > these in the memory in arrays and hash table. and i want to reload the
> > > memory automatically using some handlers. When i do this in only the
> > > particular child thread is having the updated one and the other request
> > > are showing me the old Datas.
> > >
> > > 1. The shared memory to store all the 100's of files in array and hash
> > > table which is dynamically malloced and stored will be too costly also
> > > the synchronization.
> > > IS there any other way we can overcome this.
> > >
> > > 2. Is there any way a handler can directly access the parent process,
> > > updating the memory and removing the child process which has the old Data
> > > and spawning the new child process. Can we use the mod_balancing
> > > technique of blocking the request to the server and then update the
> > > parent and kill the child and spawn new childrens with the updated memory.
> > >
> > > Please guide me with you ideas.
> >
> > Killing processes at each update is not efficient.
> >
> > I would propose the following approach:
> >
> > Hook post_config. This one is executed once by the parent process
> > before any child is spawned. Therefore, any resource opened there is
> > inherited by all child processes. Thus, I would create _shared_ memory
> > structures (see apr_shm.h, not malloc).
> >
> > Beware, post_config is run every time the server configuration is
> > reloaded. Therefore, such shared memory structures would be created
> > after each config reload. In order to avoid eating up the system's
> > resources, you'll have to make sure that each created structure is
> > also destroyed. In order to do this, _register_ a function (see
> > apr_pool_register_cleanup) that is called when the conf pool is
> > destroyed. This function would destroy the shared memory structures.
> >
> > Next, in child_init, _attach_ to the shared memory segment (see
> > apr_shm.h). From then on, the shared memory structures are shared
> > among all child processes. Each change is visible instantly in all
> > processes.
> >
> > Obviously, think of synchronisation. When not every atomic change
> > results in a consistent state of the shared data, you'll have to
> > protect the shared data with mutexes. See apr_thread_mutex.h and
> > apr_thread_rwlock.h and maybe others. Mutexes should be created in
> > post_config too.
> >
> > I hope this helps. You can contact me for a code sample if you want. I
> > don't have it handy for the moment, but I can find it.
> >
> > S
> >
> >
> > --
> > A: Because it reverses the logical flow of conversation.
> > Q: Why is top-posting frowned upon?
> > A: Top-posting.
> > Q: What is the most annoying thing in e-mail?
>
> _________________________________________________________________
> Register once and play all contests. Increase your scores with bonus credits
> for logging in daily on MSN.
> http://specials.msn.co.in/msncontest/index.aspx
_________________________________________________________________
Searching for the best deals on travel? Visit MSN Travel.
http://in.msn.com/coxandkings