source: GTP/trunk/Lib/Vis/Preprocessing/src/havran/allocgo2.h @ 2582

Revision 2582, 3.7 KB checked in by bittner, 17 years ago (diff)

Havran Ray Caster compiles and links, but still does not work

Line 
1// ===================================================================
2// $Id: allocgo2.h $
3//
4// allocgo2.h
5//     Header file for different type of allocators
6//
7// Class: CAllocator, CAllocSub
8//
9// REPLACEMENT_STRING
10//
11// Copyright by Vlastimil Havran, 2006 - email to "vhavran AT seznam.cz"
12// Initial coding by Vlastimil Havran, November 2005
13
14#ifndef __ALLOCGO2_H__
15#define __ALLOCGO2_H__
16
17// GOLEM headers
18#include "configh.h"
19
20namespace GtpVisibilityPreprocessor {
21
22// ------------------------------------------------------------------------
23// ************* size-equal item allocator with alligning in the cache ****
24
25// size-equal item allocator for ordinary subtree representation with cache
26// line alligning, sizeItem is the size of the smallest allocated block,
27// count is the number of items to perform one skip in the allocator forward
28// -------------------------------------------------------------------------
29class CAllocContinuous
30{
31public:
32  // constructor .. the size of one allocated item in Bytes,  number of items
33  // allocated in one block, the allignment for one entry, the allignment
34  // for the first allocated variable in the new blcok.
35  CAllocContinuous(int sizeEntryV, int numEntriesInBlock,
36                   int maxItemsForAllocation = 1,
37                   int allignEntrySizeV = 1,
38                   int allignBlockSizeV = 1);
39  ~CAllocContinuous() { ReleaseMemory(); }
40
41  // alloc the memory of size "sizeItem*entriesCnt" alligned in the memory
42  // started in the new block
43  void* NewEntryInNewBlock(int entriesCnt = 1);
44 
45  // alloc the memory of size "sizeItem*entriesCnt" alligned in the memory
46  // it has to be in the current block
47  void* New(int entriesCnt = 1);
48
49  // alloc the memory of size "sizeItem*entriesCnt" alligned in the memory
50  // it can be in the current block, which is definitely the last one in
51  // the current block. This should be used only if function New() above
52  // returns 0.
53  void* NewLastEntry(int entriesCnt = 1);
54
55  // alloc next block of size = granularity and returns the address to
56  // the first entry to be allocated in the next allocation by New() functions
57  void* AllocNewBlock();
58 
59#if 0
60  // alloc the memory of size "sizeItem*entriesCnt" alligned in the memory
61  // it has to be in the current block, but it is alligned to the allignment
62  // specified as the parameter.
63  void* NewAlligned(it entriesCnt = 1, int allignment = 4);
64#endif
65   
66  void ReleaseMemory(); // releases all memory alloc. by Alloc
67
68  // Returns the allignment
69  unsigned long GetEntryAllignment() const { return allignEntrySize;}
70  unsigned long GetBlockAllignment() const { return allignBlockSize;}
71  unsigned long GetFreeEntryCnt() const { return remainItems; }
72  unsigned long GetBytesAllocated() const { return bytesAllocated;}
73 
74  void Report();
75private:
76 
77  // Input variables
78  int granularity; // num of basic items in one block
79  int sizeOfEntry;  // size of one item to be allocated
80  int maxItemsAtOnce; // the number of items to be allocated at once
81  int allignBlockSize; // the allignment of the first entry in the block
82  int allignEntrySize; // the allignment of the individual entry
83
84  // The memory required to allocate for a new block
85  unsigned long memoryForOneBlock;
86
87  // The status variables
88  unsigned long bytesAllocated;  // the count of bytes allocated by this allocator
89  void *initMemBlock; // initial memory block
90  void *lastValidAddress; // the maximum address to be used in the current block
91  void **mstor; // where store allocated memory
92  char *nextAllocp; // next returned addr
93  bool lastEntryInBlockAllocated; // if we have allready used the last entry in the block
94  unsigned long remainItems; // items remains in the block
95};
96
97}
98
99#endif // __ALLOCGO2_H__
100
Note: See TracBrowser for help on using the repository browser.