library: libCore #include "TMapFile.h" |
TMapFile
class description - source file - inheritance tree (.pdf)
protected:
TMapFile()
TMapFile(const char* name, const char* title, Option_t* option, Int_t size, TMapFile*& newMapFile)
TMapFile(const TMapFile& f, Long_t offset = 0)
Int_t AcquireSemaphore()
void CreateSemaphore(Int_t pid = 0)
void DeleteSemaphore()
TMapFile* FindShadowMapFile()
Int_t GetBestBuffer()
void InitDirectory()
static void* MapToAddress()
void operator=(const TMapFile& rhs)
Int_t ReleaseSemaphore()
TObject* Remove(TObject* obj, Bool_t lock)
TObject* Remove(const char* name, Bool_t lock)
void SumBuffer(Int_t bufsize)
public:
virtual ~TMapFile()
void Add(const TObject* obj, const char* name)
virtual void Browse(TBrowser* b)
Bool_t cd(const char* path = "0")
static TClass* Class()
void Close(Option_t* option)
static TMapFile* Create(const char* name, Option_t* option = "READ", Int_t size = kDefaultMapSize, const char* title)
TObject* Get(const char* name, TObject* retObj = 0)
void* GetBaseAddr() const
void* GetBreakval() const
TDirectory* GetDirectory() const
Int_t GetFd() const
TMapRec* GetFirst() const
TMapRec* GetLast() const
void* GetMmallocDesc() const
virtual const char* GetName() const
virtual const char* GetOption() const
Int_t GetSize() const
virtual const char* GetTitle() const
virtual TClass* IsA() const
virtual Bool_t IsFolder() const
Bool_t IsWritable() const
virtual void ls(Option_t* option) const
static void operator delete(void* vp)
void* OrgAddress(void* addr) const
virtual void Print(Option_t* option) const
TObject* Remove(TObject* obj)
TObject* Remove(const char* name)
void RemoveAll()
static void SetMapAddress(Long_t addr)
virtual void ShowMembers(TMemberInspector& insp, char* parent)
virtual void Streamer(TBuffer& b)
void StreamerNVirtual(TBuffer& b)
void Update(TObject* obj = 0)
static TMapFile* WhichMapFile(void* addr)
private:
Int_t fFd Descriptor of mapped file
Int_t fVersion ROOT version (or -1 for shadow map file)
char* fName Name of mapped file
char* fTitle Title of mapped file
char* fOption Directory creation options
void* fMmallocDesc Pointer to mmalloc descriptor
ULong_t fBaseAddr Base address of mapped memory region
Int_t fSize Original start size of memory mapped region
TMapRec* fFirst List of streamed objects is shared memory
TMapRec* fLast Last object in list of shared objects
Long_t fOffset Offset in bytes for region mapped by reader
TDirectory* fDirectory Pointer to directory associated to this mapfile
TList* fBrowseList List of KeyMapFile objects
Bool_t fWritable TRUE if mapped file opened in RDWR mode
Int_t fSemaphore Modification semaphore (or getpid() for WIN32)
ULong_t fhSemaphore HANDLE of WIN32 Mutex object to implement semaphore
TObject* fGetting Don't deadlock in update mode, when from Get() Add() is called
Int_t fWritten Number of objects written sofar
Double_t fSumBuffer Sum of buffer sizes of objects written sofar
Double_t fSum2Buffer Sum of squares of buffer sizes of objects written so far
static Long_t fgMapAddress Map to this address, set address via SetMapAddress()
static void* fgMmallocDesc Used in Close() and operator delete()
public:
static const enum TMapFile:: kDefaultMapSize
void InitDirectory()
Create the directory associated to this mapfile
void Add(const TObject *obj, const char *name)
Add an object to the list of objects to be stored in shared memory.
To place the object actually into shared memory call Update().
void Update(TObject *obj)
Update an object (or all objects, if obj == 0) in shared memory.
TObject* Remove(TObject *obj, Bool_t lock)
Remove object from shared memory. Returns pointer to removed
object if successful, 0 otherwise.
TObject* Remove(const char *name, Bool_t lock)
Remove object by name from shared memory. Returns pointer to removed
object if successful, 0 otherwise.
void RemoveAll()
Remove all objects from shared memory.
TObject* Get(const char *name, TObject *delObj)
Return pointer to object retrieved from shared memory. The object must
be deleted after use. If delObj is a pointer to a previously allocated
object it will be deleted. Returns 0 in case object with the given
name does not exist.
void CreateSemaphore(int)
#else
void TMapFile::CreateSemaphore(int pid)
#endif
Create semaphore used for synchronizing access to shared memory.
void DeleteSemaphore()
Delete the semaphore.
Int_t AcquireSemaphore()
Acquire semaphore. Returns 0 if OK, -1 on error.
Int_t ReleaseSemaphore()
Release semaphore. Returns 0 if OK, -1 on error.
void Close(Option_t *option)
Close a mapped file. First detach mapped memory then close file.
No member functions of a TMapFile that was opened in write mode
may be called after Close() (this includes, of course, "delete" which
would call the dtors). The option="dtor" is only used when called
via the ~TMapFile.
TMapFile* FindShadowMapFile()
Returns shadow map file.
void Print(Option_t *) const
Print some info about the mapped file.
Bool_t IsFolder() const
Returns kTRUE in case object is a folder (i.e. contains browsable lists).
void Browse(TBrowser *b)
Browse contents of TMapFile.
Bool_t cd(const char *path)
Cd to associated directory,
void ls(Option_t *) const
List contents of TMapFile.
void SumBuffer(Int_t bufsize)
Increment statistics for buffer sizes of objects in this file.
Int_t GetBestBuffer()
Return the best buffer size for objects in this file.
The best buffer size is estimated based on the current mean value
and standard deviation of all objects written so far to this file.
Returns mean value + one standard deviation.
TMapFile* Create(const char *name, Option_t *option, Int_t size,
const char *title)
Create a memory mapped file. This opens a file (to which the
memory will be mapped) and attaches a memory region to it.
Option can be either: "NEW", "CREATE", "RECREATE", "UPDATE"
or "READ" (see TFile). The default open mode is "READ". The size
argument specifies the maximum size of shared memory file in bytes.
TMapFile's can only be created via this method. Create() enforces that
a TMapFile is always on the memory mapped heap (when "NEW", "CREATE"
or "RECREATE" are used).
void SetMapAddress(Long_t addr)
Set preferred map address. Find out preferred map address as follows:
1) Run consumer program to find the preferred map address:
$ root
root [0] m = TMapFile::Create("dummy.map", "recreate", 10000000);
root [1] m.Print()
Memory mapped file: dummy.map
Title:
Option: CREATE
Mapped Memory region: 0x40b4c000 - 0x40d95f00 (2.29 MB)
Current breakval: 0x40b53000
root [2] .q
$ rm dummy.map
Remember begin of mapped region, i.e. 0x40b4c000
2) Add to producer program, just before creating the TMapFile:
TMapFile::SetMapAddress(0x40b4c000);
Repeat this if more than one map file is being used.
The above procedure allow programs using, e.g., different number of
shared libraries (that cause the default mapping address to be
different) to create shared memory regions in the same location
without overwriting a shared library. The above assumes the consumer
program is larger (i.e. has more shared memory occupied) than the
producer. If this is not true inverse the procedure.
void* MapToAddress()
Return the base address at which we would like the next TMapFile's
mapped data to start.
For now, we let the system decide (start address 0). There are
a lot of issues to deal with here to make this work reasonably,
including:
- Avoid memory collisions with existing mapped address spaces
- Reclaim address spaces when their mmalloc heaps are unmapped
- When mmalloc heaps are shared between processes they have to be
mapped at the same addresses in each
Once created, a mmalloc heap that is to be mapped back in must be
mapped at the original address. I.E. each TMapFile will expect
to be remapped at it's original address. This becomes a problem if
the desired address is already in use.
Inline Functions
void ~TMapFile()
TMapFile TMapFile()
TMapFile TMapFile(const char* name, const char* title, Option_t* option, Int_t size, TMapFile*& newMapFile)
TMapFile TMapFile(const TMapFile& f, Long_t offset = 0)
void operator=(const TMapFile& rhs)
void operator delete(void* vp)
void* GetBaseAddr() const
void* GetBreakval() const
TDirectory* GetDirectory() const
Int_t GetFd() const
void* GetMmallocDesc() const
const char* GetName() const
Int_t GetSize() const
const char* GetOption() const
const char* GetTitle() const
TMapRec* GetFirst() const
TMapRec* GetLast() const
Bool_t IsWritable() const
void* OrgAddress(void* addr) const
TObject* Remove(TObject* obj)
TObject* Remove(const char* name)
TMapFile* WhichMapFile(void* addr)
TClass* Class()
TClass* IsA() const
void ShowMembers(TMemberInspector& insp, char* parent)
void Streamer(TBuffer& b)
void StreamerNVirtual(TBuffer& b)
Author: Fons Rademakers 08/07/97
Last update: root/base:$Name: $:$Id: TMapFile.cxx,v 1.15 2005/04/18 16:05:48 rdm Exp $
Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
ROOT page - Class index - Class Hierarchy - Top of the page
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.