The Gaudi Framework  master (37c0b60a)
IgHookTraceAlloc Class Reference

#include </builds/gaudi/Gaudi/GaudiProfiling/src/component/IgHook_IgHookTrace.h>

Public Member Functions

 IgHookTraceAlloc (void)
 
void * allocate (size_t bytes)
 

Private Attributes

void * m_pool
 
size_t m_left
 

Detailed Description

Definition at line 26 of file IgHook_IgHookTrace.h.

Constructor & Destructor Documentation

◆ IgHookTraceAlloc()

IgHookTraceAlloc::IgHookTraceAlloc ( void  )

Definition at line 109 of file IgHook_IgHookTrace.cpp.

109 : m_pool( 0 ), m_left( 0 ) {}

Member Function Documentation

◆ allocate()

void * IgHookTraceAlloc::allocate ( size_t  bytes)

Definition at line 111 of file IgHook_IgHookTrace.cpp.

111  {
112  // The reason for the existence of this class is to allocate
113  // memory directly using mmap() so we don't create calls to
114  // malloc() and friends. This is for two reasons: it must be
115  // possible to use this in asynchronous signal handlers, and
116  // calling malloc() in those is a really bad idea; and this is
117  // meant to be used by profiling code and it's nicer to not
118  // allocate memory in ways tracked by the profiler.
119  if ( m_left < bytes ) {
120  size_t psize = getpagesize();
121  size_t hunk = psize * 20;
122  if ( hunk < bytes ) hunk = ( hunk + psize - 1 ) & ~( psize - 1 );
123  void* addr = mmap( 0, hunk, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0 );
124  if ( addr == MAP_FAILED ) return 0;
125 
126  m_pool = addr;
127  m_left = hunk;
128  }
129 
130  void* ptr = m_pool;
131  m_pool = (char*)m_pool + bytes;
132  m_left -= bytes;
133  return ptr;
134 }

Member Data Documentation

◆ m_left

size_t IgHookTraceAlloc::m_left
private

Definition at line 34 of file IgHook_IgHookTrace.h.

◆ m_pool

void* IgHookTraceAlloc::m_pool
private

Definition at line 33 of file IgHook_IgHookTrace.h.


The documentation for this class was generated from the following files:
IgHookTraceAlloc::m_pool
void * m_pool
Definition: IgHook_IgHookTrace.h:33
IgHookTraceAlloc::m_left
size_t m_left
Definition: IgHook_IgHookTrace.h:34