Mobile API Reference  MicroStrategy 2019
Buffer.h
Go to the documentation of this file.
1 //==============================================================================================
2 // FILENAME : Base.h
3 // AUTHOR : Wayne Li
4 // CREATION : 9/26/1996
5 // Copyright (C) MicroStrategy Incorporated 1996
6 // All Rights Reserved
7 //==============================================================================================
8 #ifndef MBase_Buffer_h
9 #define MBase_Buffer_h
10 
11 #include "PDCHeader/PDCstddef.h"
12 #include "Base.h"
13 #ifndef __ANDROID__
15 #endif
16 #include "Base/Defines/StrongPtr.h"
17 
18 #include "Base/Base/NewOperator.h"
19 
20 // Ensure that the new operator for buffer has been defined, and that the new
21 // operator that reports leaks has been defined.
22 // If the new operator of buffer is used, but is not defined, it will call the
23 // placement new operator (MBase::Buffer* will be implicitly upcasted to void*),
24 // and we will get an AV.
25 #ifdef WIN32
26  #ifndef _BUFFER_NEW_OPERATOR_DEFINED_
27  #ifndef _OBJECT_DUMP_NEW_OPERATOR_DEFINED_
28  #define _NEW_OPERATOR_UNDEFINED_
29  #define new _NEW_OPERATOR_NOT_DEFINED_
30  #endif
31  #endif
32 #endif
33 
34 namespace MBase
35 {
58  class Buffer
59  {
60  public:
62  {
65  };
66 
67  virtual void Delete() throw() = 0;
68 
69  // Allocates a chunk of memory according to the size.
70  // Any further memory request will be allocated from this chunk until the chunk is used up.
71  // return true if success
72  virtual bool Reserve(size_t iSize) = 0;
73 
74  // Returns a pointer to the memory (equivalent of doing a new)
75  // throws BufferException if buffer was previously locked
76  // throws ContractManagerException (defined in BaseMemoryContract.h)
77  virtual void* GetMem(size_t iSize) = 0;
78 
79  // returns the total memory reserved by the buffer, in KB
80  virtual unsigned Int32 GetTotalMemSize() const = 0;
81 
82  // returns the total memory reserved AND used by the buffer, in KB
83  virtual unsigned Int32 GetAllocMemSize() const = 0;
84 
85  //xfan. 4/13/09, TQMS 354241. Add new interface
86  virtual unsigned Int64 GetTotalMemSizeInBytes() const = 0;
87  virtual unsigned Int64 GetAllocMemSizeInBytes() const = 0;
88 
89  // Use this function to make the buffer "read-only"
90  // when this function is called the memory contained by the
91  // the buffer gets locked from writes
92  // throws BufferException if unable to lock
93  virtual void WriteLock() = 0;
94 
95  // set the maxium limit for the total allocated space size, if the size is over the limit,
96  // the buffer.GetMem operation will throw an BufferException
97  // it is currently to be used by SQL Engine only
98  virtual void SetTotalAllocatedSpaceLimit(Int64 iLimit) = 0;
99 
100 // protected:
101  virtual ~Buffer() throw()
102  {
103  };
104  };
105 
106  class MemoryContract;
107 
109  // Factory Functions
110 
112  // xfan, add comments. 12/06/07
113  // iSize is the initial block number, iExtSize is each incremental block number.
114  // iBlkSize is block size.
115  // if ibOnPageBoundary is set to true, it will allocate/return memory directly from OS;
116  // and the memory will be allocated at least one page.
117  // if ibOnPageBoundary is false, it will though the memory menager such as smartheap
118  DLL_BASE_EXIM Buffer* CreateBuffer(Int32 iSize,Int32 iExtSize,
119  Int32 iBlkSize = Buffer::NT_BLOCK_SIZE,
120  bool ibOnPageBoundary = false);
121 
123  DLL_BASE_EXIM Buffer* CreateBuffer(Int32 iSize,Int32 iExtSize,
124  MBase::MemoryContract* ipMemoryContract,
125  Int32 iBlkSize = Buffer::NT_BLOCK_SIZE,
126  bool ibOnPageBoundary = false);
127 
129 #ifndef __ANDROID__
131  {
132  };
133 #endif
134 }
135 
136 #endif // MBase_Buffer_h
Definition: BaseMemoryContract.h:40
Definition: Buffer.h:58
#define Int64
Definition: BasicTypes.h:36
virtual bool Reserve(size_t iSize)=0
StrongPtr< Buffer, DeleteOperatorGeneric< Buffer > > BufferPtr
Definition: Buffer.h:128
virtual void SetTotalAllocatedSpaceLimit(Int64 iLimit)=0
#define DLL_BASE_EXIM
Definition: Base.h:20
virtual void Delete()=0
#define Int32
Definition: BasicTypes.h:20
Definition: Message.h:32
virtual unsigned Int32 GetTotalMemSize() const =0
Definition: Allocator.h:47
Definition: Buffer.h:64
Definition: StrongPtr.h:50
Definition: Buffer.h:63
virtual void WriteLock()=0
virtual unsigned Int64 GetTotalMemSizeInBytes() const =0
BlockSizes
Definition: Buffer.h:61
DLL_BASE_EXIM Buffer * CreateBuffer(Int32 iSize, Int32 iExtSize, Int32 iBlkSize=Buffer::NT_BLOCK_SIZE, bool ibOnPageBoundary=false)
throws ContractManagerException (defined in BaseMemoryContract.h)
Definition: Buffer.h:130
virtual unsigned Int64 GetAllocMemSizeInBytes() const =0
virtual void * GetMem(size_t iSize)=0
virtual unsigned Int32 GetAllocMemSize() const =0