CMS 3D CMS Logo

IgHookTraceAlloc Class Reference

#include <IgTools/IgHook/interface/IgHookTrace.h>

List of all members.

Public Member Functions

voidallocate (size_t bytes)
 IgHookTraceAlloc (void)

Private Attributes

size_t m_left
voidm_pool


Detailed Description

Definition at line 15 of file IgHookTrace.h.


Constructor & Destructor Documentation

IgHookTraceAlloc::IgHookTraceAlloc ( void   ) 

Definition at line 75 of file IgHookTrace.cc.

00076     : m_pool (0),
00077       m_left (0)
00078 {}


Member Function Documentation

void * IgHookTraceAlloc::allocate ( size_t  bytes  ) 

Definition at line 81 of file IgHookTrace.cc.

References addr, m_left, m_pool, mmap, and ptr.

Referenced by IgHookTrace::operator new(), and IgHookTrace::CounterValue::operator new().

00082 {
00083     // The reason for the existence of this class is to allocate
00084     // memory directly using mmap() so we don't create calls to
00085     // malloc() and friends.  This is for two reasons: it must be
00086     // possible to use this in asynchronous signal handlers, and
00087     // calling malloc() in those is a really bad idea; and this is
00088     // meant to be used by profiling code and it's nicer to not
00089     // allocate memory in ways tracked by the profiler.
00090     if (m_left < bytes)
00091     {
00092         size_t psize = getpagesize ();
00093         size_t hunk = psize * 20;
00094         if (hunk < bytes) hunk = (hunk + psize - 1) & ~(psize-1);
00095         void *addr = mmap (0, hunk, PROT_READ | PROT_WRITE,
00096                            MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
00097         if (addr == MAP_FAILED)
00098             return 0;
00099 
00100         m_pool = addr;
00101         m_left = hunk;
00102     }
00103 
00104     void *ptr = m_pool;
00105     m_pool = (char *) m_pool + bytes;
00106     m_left -= bytes;
00107     return ptr;
00108 }


Member Data Documentation

size_t IgHookTraceAlloc::m_left [private]

Definition at line 24 of file IgHookTrace.h.

Referenced by allocate().

void* IgHookTraceAlloc::m_pool [private]

Definition at line 23 of file IgHookTrace.h.

Referenced by allocate().


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:25:12 2009 for CMSSW by  doxygen 1.5.4