KaliVeda
Toolkit for HIC analysis
KVMemoryPool.cpp
1 //Created by KVClassFactory on Fri Oct 1 16:50:02 2010
2 //Author: John Frankland,,,,
3 
4 #include "KVMemoryPool.h"
5 
7 
8 
9 
10 
13 KVMemoryPool::KVMemoryPool(int nchunks, size_t bytes)
14 {
15  // Create nchunks chunks each of size 'bytes'
16  fFirst = fLast = fLastChunkUsed = 0;
17  for (int i = 0; i < nchunks; i++) {
18  KVMemoryChunk* chunk = new KVMemoryChunk(bytes);
19  if (!fFirst) fFirst = chunk;
20  if (fLast) fLast->SetNext(chunk);
21  fLast = chunk;
22  }
23  fLastChunkUsed = fFirst;
24  fChunkSize = bytes;
25 }
26 
27 
28 
31 
32 void* KVMemoryPool::GetMemory(size_t bytes)
33 {
34  // return pointer to memory of size 'bytes'
35  void* p = fFirst->GetMemory(bytes);
37  if (!p) {
38  // search for first available chunk which can provide memory
39  do {
42  }
43  while (!p && fLastChunkUsed);
44  }
45  if (!p) {
46  // there are no chunks big enough to provide memory
47  // add a bigger chunk
48  size_t new_chunk = fChunkSize;
49  while (new_chunk < bytes) new_chunk *= 2;
50  fChunkSize = new_chunk;
52  fLast->SetNext(chunk);
53  fLast = chunk;
54  fLastChunkUsed = chunk;
56  }
57  return p;
58 }
59 
60 
61 
64 
66 {
67  // Destructor
69  KVMemoryChunk* next;
70  while (p) {
71  next = p->Next();
72  delete p;
73  p = next;
74  }
75 }
76 
77 
78 
80 
82 {
84  while (p) {
85  p->Print();
86  p = p->Next();
87  }
88 }
89 
90 
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t bytes
T1 fFirst
Memory handled by KVMemoryPool.
Definition: KVMemoryChunk.h:15
KVMemoryChunk * Next() const
Definition: KVMemoryChunk.h:32
void SetNext(KVMemoryChunk *n)
Definition: KVMemoryChunk.h:28
void * GetMemory(size_t)
Managed pool of memory.
Definition: KVMemoryPool.h:15
void * GetMemory(size_t bytes)
return pointer to memory of size 'bytes'
size_t fChunkSize
size of chunks in bytes
Definition: KVMemoryPool.h:19
KVMemoryChunk * fLastChunkUsed
Definition: KVMemoryPool.h:18
virtual ~KVMemoryPool()
Destructor.
KVMemoryChunk * fLast
first chunk in pool
Definition: KVMemoryPool.h:17
KVMemoryChunk * fFirst
first chunk in pool
Definition: KVMemoryPool.h:16
virtual void Print(Option_t *option="") const
ClassImp(TPyArg)