class TMapRec


TMapFile

This class implements a shared memory region mapped to a file.
Objects can be placed into this shared memory area using the Add()
member function. To actually place a copy of the object is shared
memory call Update() also whenever the mapped object(s) change(s)
call Update() to put a fresh copy in the shared memory. This extra
step is necessary since it is not possible to share objects with
virtual pointers between processes (the vtbl ptr points to the
originators unique address space and can not be used by the
consumer process(es)). Consumer processes can map the memory region
from this file and access the objects stored in it via the Get()
method (which returns a copy of the object stored in the shared
memory with correct vtbl ptr set). Only objects of classes with a
Streamer() member function defined can be shared.

I know the current implementation is not ideal (you need to copy to
and from the shared memory file) but the main problem is with the
class' virtual_table pointer. This pointer points to a table unique
for every process. Therefore, different options are:
1) One could allocate an object directly in shared memory in the
producer, but the consumer still has to copy the object from
shared memory into a local object which has the correct vtbl
pointer for that process (copy ctor's can be used for creating
the local copy).
2) Another possibility is to only allow objects without virtual
functions in shared memory (like simple C structs), or to
forbid (how?) the consumer from calling any virtual functions
of the objects in shared memory.
3) A last option is to copy the object internals to shared memory
and copy them again from there. This is what is done in the
TMapFile (using the object Streamer() to make a deep copy).
Option 1) saves one copy, but requires solid copy ctor's (along the
full inheritance chain) to rebuild the object in the consumer. Most
classes don't provide these copy ctor's, especially not when objects
contain collections, etc. 2) is too limiting or dangerous (calling
accidentally a virtual function will segv). So since we have a
robust Streamer mechanism I opted for 3).


Function Members (Methods)

public:
TMapRec(const TMapRec&)
TMapRec(const char* name, const TObject* obj, Int_t size, void* buf)
~TMapRec()
void*GetBuffer(Long_t offset = 0) const
Int_tGetBufSize() const
const char*GetClassName(Long_t offset = 0) const
const char*GetName(Long_t offset = 0) const
TMapRec*GetNext(Long_t offset = 0) const
TObject*GetObject() const
TMapRec&operator=(const TMapRec&)

Data Members

private:
Int_tfBufSizebuffer size
void*fBufferbuffer containing object of class name
char*fClassNameclass name
char*fNameobject name
TMapRec*fNextnext MapRec in list
TObject*fObjectpointer to original object

Class Charts

Inheritance Inherited Members Includes Libraries
Class Charts

Function documentation

TMapRec(const char* name, const TObject* obj, Int_t size, void* buf)
 Constructor.
~TMapRec()
 Destructor.
TObject * GetObject()
 This method returns a pointer to the original object. NOTE: this pointer
 is only valid in the process that produces the shared memory file. In a
 consumer process this pointer is illegal! Be careful.
void operator=(const TMapRec& )
const char * GetName(Long_t offset = 0) const
{ return fName; }
TMapRec(const char* name, const TObject* obj, Int_t size, void* buf)
const char * GetClassName(Long_t offset = 0) const
{ return (char *)((Long_t) fClassName + offset); }
void * GetBuffer(Long_t offset = 0) const
{ return (void *)((Long_t) fBuffer + offset); }
Int_t GetBufSize()
{ return fBufSize; }
TMapRec * GetNext(Long_t offset = 0) const
{ return (TMapRec *)((Long_t) fNext + offset); }

Author: Fons Rademakers 08/07/97
Last change: root/io:$Id: TMapFile.h 23122 2008-04-10 14:56:30Z rdm $
Last generated: 2008-06-25 08:49
Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *

This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.