KaliVeda  1.13/01
Heavy-Ion Analysis Toolkit
KVMemoryChunk.cpp
Go to the documentation of this file.
1 //Created by KVClassFactory on Fri Oct 1 16:50:15 2010
2 //Author: John Frankland,,,,
3 
4 #include "KVMemoryChunk.h"
5 #include <cstdlib>
6 
8 
9 
10 
14  : fMemory(0), fSize(0), fUsed(0), fNext(0)
15 {
16  // Default constructor
17 }
18 
19 
20 
23 
24 KVMemoryChunk::KVMemoryChunk(size_t bytes) : fNext(0)
25 {
26  // Allocate new chunk of size 'bytes'
27  fMemory = (char*) malloc(bytes);
28  fSize = bytes;
29  fUsed = 0;
30 }
31 
32 
33 
36 
38 {
39  // Destructor
40  if (fMemory) free(fMemory);
41  fMemory = 0;
42 }
43 
44 
45 
49 
50 void* KVMemoryChunk::GetMemory(size_t bytes)
51 {
52  // Return pointer to block of memory of size 'bytes'
53  // If no block of this size is available, returns 0 (test it!!)
54 
55  if (fUsed + bytes <= fSize) {
56  void* p = (void*)(fMemory + fUsed);
57  fUsed += bytes;
58  return p;
59  }
60  return NULL;
61 }
62 
63 
65 
67 {
68  printf("KVMemoryChunk: %lu bytes (%lu used) at: %p\n",
69  fSize, fUsed, fMemory);
70 };
71 
72 
73 
ClassImp(KVPartitionList) void KVPartitionList
Initialisation.
#define free
#define malloc
Memory handled by KVMemoryPool.
Definition: KVMemoryChunk.h:14
virtual ~KVMemoryChunk()
Destructor.
size_t fSize
size of chunk in bytes
Definition: KVMemoryChunk.h:16
char * fMemory
pointer to start of chunk
Definition: KVMemoryChunk.h:15
void * GetMemory(size_t)
size_t fUsed
memory used in bytes
Definition: KVMemoryChunk.h:17
KVMemoryChunk()
Default constructor.