CUBRID Engine  latest
pinnable_buffer.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2008 Search Solution Corporation
3  * Copyright 2016 CUBRID Corporation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 /*
20  * pinnable_buffer.hpp
21  */
22 
23 #ifndef _PINNABLE_BUFFER_HPP_
24 #define _PINNABLE_BUFFER_HPP_
25 
26 #ident "$Id$"
27 
28 #include "dbtype.h"
29 #include "pinning.hpp"
30 #include <atomic>
31 #include <vector>
32 
33 /*
34  * This should serve as storage for packing / unpacking objects
35  * This is not intended to be used as character stream, but as bulk operations: users of it
36  * reserve / allocate parts of it; there are objects which deal of byte level operations (see : packer)
37  */
38 namespace cubmem
39 {
40 
42  {
43  public:
45  {
46  m_storage = NULL;
47  m_end_ptr = NULL;
48  };
49 
50  pinnable_buffer (char *ptr, const size_t buf_size)
51  {
52  init (ptr, buf_size, NULL);
53  };
54 
56  {
57  assert (get_pin_count () == 0);
58  };
59 
60  char *get_buffer (void)
61  {
62  return m_storage;
63  };
64 
65  size_t get_buffer_size (void)
66  {
67  return m_end_ptr - m_storage;
68  };
69 
70  int init (char *ptr, const size_t buf_size, cubbase::pinner *referencer);
71 
72  protected:
73 
74  /* start of allocated memory */
75  char *m_storage;
76  /* end of allocated memory */
77  char *m_end_ptr;
78  };
79 
80 } /* namespace mem */
81 
82 #endif /* _PINNABLE_BUFFER_HPP_ */
pinnable_buffer(char *ptr, const size_t buf_size)
int init(char *ptr, const size_t buf_size, cubbase::pinner *referencer)
int get_pin_count(void)
Definition: pinning.hpp:74
#define assert(x)
#define NULL
Definition: freelistheap.h:34