Mobile API Reference  MicroStrategy 2019
SimpleBuffer.h
Go to the documentation of this file.
1 //==============================================================================================
2 // FILENAME : SimpleBuffer.h
3 // AUTHOR : ydong
4 // CREATION : 1/28/2013
5 // Copyright (C) MicroStrategy Incorporated 2001
6 // All Rights Reserved
7 //==============================================================================================
8 #ifndef MBase_SimpleBuffer_h
9 #define MBase_SimpleBuffer_h
10 
11 #include <vector>
12 
13 #include "Base/Base/Buffer.h"
14 
15 
16 namespace MBase
17 {
18  //No Lock, auto release memory when destructure.
19  class SimpleBuffer : public Buffer
20  {
21  public:
23  mBuffer(){}
24  virtual void Delete() throw() {
25  for(size_t i=0; i<mBuffer.size(); ++i)
26  delete [] mBuffer[i].first;
27  mBuffer.clear();
28  }
29 
30  // Allocates a chunk of memory according to the size.
31  // Any further memory request will be allocated from this chunk until the chunk is used up.
32  // return true if success
33  virtual bool Reserve(size_t iSize) { return false; }
34 
35  // Returns a pointer to the memory (equivalent of doing a new)
36  // throws BufferException if buffer was previously locked
37  // throws ContractManagerException (defined in BaseMemoryContract.h)
38  virtual void* GetMem(size_t iSize) {
39  unsigned char* lBuffer = new unsigned char[iSize];
40  mBuffer.push_back(MemBlock(lBuffer, iSize));
41  return lBuffer;
42  }
43 
44  // returns the total memory reserved by the buffer, in KB
45  virtual unsigned Int32 GetTotalMemSize() const { return -1; }
46 
47  // returns the total memory reserved AND used by the buffer, in KB
48  virtual unsigned Int32 GetAllocMemSize() const { return -1; }
49 
50  //xfan. 4/13/09, TQMS 354241. Add new interface
51  virtual unsigned Int64 GetTotalMemSizeInBytes() const { return -1; }
52  virtual unsigned Int64 GetAllocMemSizeInBytes() const { return -1; }
53 
54  // Use this function to make the buffer "read-only"
55  // when this function is called the memory contained by the
56  // the buffer gets locked from writes
57  // throws BufferException if unable to lock
58  virtual void WriteLock() {}
59 
60  // set the maxium limit for the total allocated space size, if the size is over the limit,
61  // the buffer.GetMem operation will throw an BufferException
62  // it is currently to be used by SQL Engine only
63  virtual void SetTotalAllocatedSpaceLimit(Int64 iLimit) {}
64 
65  typedef std::pair<unsigned char*, int> MemBlock;
66  typedef std::vector<MemBlock> MemVec;
67  ~SimpleBuffer() throw() {
68  for(size_t i=0; i<mBuffer.size(); ++i)
69  delete [] mBuffer[i].first;
70  mBuffer.clear();
71  }
72  private:
73  MemVec mBuffer;
74  };
75 }
76 
77 #endif // MBase_BufferImplementation_h
virtual unsigned Int32 GetAllocMemSize() const
Definition: SimpleBuffer.h:48
SimpleBuffer()
Definition: SimpleBuffer.h:22
std::vector< MemBlock > MemVec
Definition: SimpleBuffer.h:66
virtual bool Reserve(size_t iSize)
Definition: SimpleBuffer.h:33
virtual unsigned Int64 GetAllocMemSizeInBytes() const
Definition: SimpleBuffer.h:52
#define Int64
Definition: BasicTypes.h:36
~SimpleBuffer()
Definition: SimpleBuffer.h:67
#define Int32
Definition: BasicTypes.h:20
std::pair< unsigned char *, int > MemBlock
Definition: ReportServiceCore/Classes/common/SimpleBuffer.h:65
Definition: Allocator.h:47
virtual void WriteLock()
Definition: SimpleBuffer.h:58
virtual void Delete()
Definition: SimpleBuffer.h:24
virtual void SetTotalAllocatedSpaceLimit(Int64 iLimit)
Definition: SimpleBuffer.h:63
virtual unsigned Int32 GetTotalMemSize() const
Definition: SimpleBuffer.h:45
virtual unsigned Int64 GetTotalMemSizeInBytes() const
Definition: SimpleBuffer.h:51
virtual void * GetMem(size_t iSize)
Definition: SimpleBuffer.h:38