gatelib  2.1
g_cont_AllocationPolicyAbstract.h
1 #pragma once
2 
3 #include "g_cont_common.h"
4 #include "g_cont_HeapAbstract.h"
5 
6 namespace g
7 {
8 namespace cont
9 {
10  class G_LIB_ITEM AllocationPolicySimple;
11 
12  //empty
13  struct MemMarker {};
14 
15  //Represent the
16  class G_LIB_ITEM AllocationPolicyAbstract
17  {
18  public:
19  AllocationPolicyAbstract ( HeapAbstract* aHeapP ) : mHeapP ( aHeapP ) {}
20  virtual ~AllocationPolicyAbstract(){}
21 
22  virtual int getNumRefs ( MemMarker* ) const = 0;
23  virtual void incRef ( MemMarker* ) = 0;
28  virtual int decRef ( MemMarker* ) = 0;
29  virtual void* getRefDataLocation ( MemMarker* ) = 0;
30  virtual void* getResizableDataLocation ( MemMarker* ) = 0;
31  //version for single object(g::cont::ref) reservation (data ref)
32  virtual MemMarker* reserveRef ( size_t data_size ) = 0;
33  //version for multiple reservation (g::cont::data_ref)
34  virtual MemMarker* reserveResizableData ( size_t type_size , size_t cardinality ) = 0;
35  virtual MemMarker* resizeResizableData ( MemMarker* data_marker , size_t type_size , size_t old_cardinality , size_t cardinality ) = 0;
36 
37  //ask the heap for freeing ref data
38  virtual void freeRef ( MemMarker* ) = 0;
39  //ask the heap for freeing sizable data
40  virtual void freeResizableData ( MemMarker* ) = 0;
41 
42  HeapAbstract* getHeapP ( ) const { return mHeapP; }
43 
44  template < class T > MemMarker* reserveResizableDataT ( size_t cardinality ) { return reserveResizableData( sizeof(T) , cardinality ); }
45  //version for multiple reservation (g::cont::data_ref)
46  template < class T > MemMarker* resizeResizableDataT ( MemMarker* data_marker , size_t old_cardinality , size_t cardinality ) { return resizeResizableData( data_marker , sizeof(T) , old_cardinality , cardinality ); }
47 
48  static AllocationPolicyAbstract* get_FromStandardPolicy ( );
49 
50  //returns implementation for single thread
51  static AllocationPolicyAbstract* get_Default ( );
52  static AllocationPolicyAbstract* set_Default ( AllocationPolicyAbstract* );
53 
54  static AllocationPolicySimple* allocation_PolicySimpleP ( );
55 
56  protected:
57  HeapAbstract* mHeapP;
58  };
59 
60  //Implement ref as a simple ref counter
61  struct RefMarkerSimple : public MemMarker
62  {
63  int numRefs;
64  };
65 
66  // empty
68 
69 }//namespace g
70 }//namespace cont
71 
72 #include "g_cont_AllocationPolicySimple.h"
73 
74 
Definition: g_cont_AllocationPolicyAbstract.h:67
Definition: g_cont_AllocationPolicyAbstract.h:61
Definition: g_cont_AllocationPolicyAbstract.h:16
Definition: g.mthread.ThreadSimpleEvent.h:5
Definition: g_cont_HeapAbstract.h:20
Definition: g_cont_AllocationPolicyAbstract.h:13
Definition: g_cont_AllocationPolicySimple.h:10