Shared Memory, Apache 1.3 and other issues
I am trying to make an Apache 1.3 module Sys V shared memory, and I'm
starting to realise that my C++ skills are a bit lightweight for this... So
I'm apealing for help. Any code snippets are greatly appreciated!
1) I am using the module_init function in Apache to create the shared memory
section, but the problem is that it's called twice (the module is loaded,
unloaded, then loaded again)! Is there a way of testing if a shared memory
segment is already created, and create it only if it's not done already?
2) We need to synchronise access to the memory segment (using semaphores, I
guess), but we need some way of distinguishing between read and writes, so
that reads can happen concurently, but on write, only one process can access
the memory. Another approach might be to let the write happen to a different
part of memory (either another part of the memory segment, or a different
segment), and then swap pointers, somehow. Is this plausible?
3) The data we are trying to store in memory is in the form of C++ objects
(stored in a database as a blob, then unstreamed into memory using
ObjectSpace), and the structure is quite complex. In fact, the main overhead
that we're trying to minimise is the actual unstreaming of the data, not
necesarilly the database read. Is it best to somehow overload the new
operator to create the objects in the shared memory segment (read something
about that somewhere, but can't seem to find it again...), or can we copy it
from the process heap into shared memory, getting all the pointers updated
as well (seems to me like quite a heavy job that could easilly go wrong)?
Hope someone can help.