KaliVeda
Toolkit for HIC analysis
Loading...
Searching...
No Matches
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
12
13KVMemoryPool::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
32void* 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.
void SetNext(KVMemoryChunk *n)
void * GetMemory(size_t)
KVMemoryChunk * Next() const
Managed pool of memory.
void * GetMemory(size_t bytes)
return pointer to memory of size 'bytes'
size_t fChunkSize
size of chunks in bytes
KVMemoryChunk * fLastChunkUsed
virtual ~KVMemoryPool()
Destructor.
KVMemoryChunk * fLast
first chunk in pool
KVMemoryChunk * fFirst
first chunk in pool
virtual void Print(Option_t *option="") const
ClassImp(TPyArg)