#include <IgTools/IgHook/interface/IgHookTrace.h>
Public Member Functions | |
void * | allocate (size_t bytes) |
IgHookTraceAlloc (void) | |
Private Attributes | |
size_t | m_left |
void * | m_pool |
Definition at line 15 of file IgHookTrace.h.
IgHookTraceAlloc::IgHookTraceAlloc | ( | void | ) |
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 }
size_t IgHookTraceAlloc::m_left [private] |
void* IgHookTraceAlloc::m_pool [private] |