|go ahead... be a heretic|
|( #3333=superdoc: print w/replies, xml )||Need Help??|
Thanks xiper++ once again for the excellent feedback! :-D
I have made several improvements after reading your comments...
1) no explicit Init statement required
The default MMF namespace (shared memory) will be created if the user has not explicitly provided namespace parameters. Once initialized, all subsequent tie() will use the default namespace, unless otherwise specified in the parameter list to tie().
2) Namespace consideration
Win32::MMF has a slightly different design to IPC::Shareable in shared memory management. The following diagram is a view of a MMF namespace:
Every MMF created carries a MMF descriptor table that contains information about the size of the MMF, number of variables declared inside the namespace and heap information. Variable definition starts from the top of MMF and grows downward. The variable definition carries a pointer if there is associated data for the variable. Memory is allocated from the heap bottom and grows upward to hold the actual data. When a variable is deleted, the MMF manager deletes the variable definition and frees the memory allocated to the variable data.
A MMF contains everything a process need to know about, because all the memory management information is carried inside the MMF itself. So that when one process adds variable, another process immediately sees it, and can use it without any additional initialization steps.
The tie() wrapper does not directly control how a variable is stored inside the MMF. It doesn't care how much memory is required to store a particular tied variable, the MMF manager automatically shrinks or grows the memory allocated to the variable, as long as there is still enough memory left in the heap.
# key ĘC same as your 'varid', suggest you use this, or at least accept it as an alias
The Win32::MMF::Shareable module is designed as a drop-in replacement to IPC::Shareable under Windows, you can use it the same way as IPC::Shareable. Options like mode, destroy, are ignored. I have created the copied the following demo from then IPC::Shareable demo in the POD, replaced use IPC::Shareable to automatically switch between Win32::MMF::Shareable and IPC::Shareable on different platform, leaving the rest of the code untouched.
# The two modules Win32::MMF and Win32::MMF::Shareable, while implemented in a similar way, behave quiet differently to the user. It may be a good idea to document each separately to avoid confusion.
# In the pod: "Because memory and variable management are managed internally by the Win32::MMF module, you do not need to specify how much memory is required by the variable." Is this correct? You don't have to specify a size for a tied variable? Will it automatically expand if the data grows? If so, why not have this for non-tied variables as well?
That's correct, the MMF manager decides the correct amount of memory required inside the MMF to hold the object, so it can be correctly recreated from another process. This applies to untied variables too.
# How does your module handle the issue of when to clear the data in shared memory? I assume that it's when the last 'connected' process exits or tied variable falls out of scope, correct? What about if the process is killed (via a SIGTERM)? Any possible memory leaks? (I assume you've already covered these issues, just interested to know).
Currently it's up to Windows own memory management system to handle a killed process. Windows will destroy the MMF if all processes accessing it are killed. (A least I hope so.)
In reply to Re: Re: Re: Re: Win32::MMF - Memory Mapped File Support for Perl