CUBRID Engine  latest
parser_allocator.cpp
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 // parser_allocator.cpp - C++ extensions to parser allocation
21 //
22 
23 #include "parser_allocator.hpp"
24 
25 #include "parser.h"
26 
27 #include <cstring>
28 
30  : cubmem::block_allocator (std::bind (&parser_block_allocator::alloc, this, std::placeholders::_1,
31  std::placeholders::_2),
32  std::bind (&parser_block_allocator::dealloc, this, std::placeholders::_1))
33  , m_parser (parser)
34 {
35  //
36 }
37 
38 void
40 {
41  if (b.ptr == NULL || b.dim == 0)
42  {
43  b.ptr = (char *) parser_alloc (m_parser, (int) size);
44  b.dim = size;
45  }
46  else if (size <= b.dim)
47  {
48  // do nothing
49  }
50  else
51  {
52  size_t new_size;
53 
54  for (new_size = b.dim; new_size < size; new_size *= 2)
55  ;
56 
57  char *new_ptr = (char *) parser_alloc (m_parser, (int) new_size);
58  std::memcpy (new_ptr, b.ptr, b.dim);
59 
60  // no freeing
61  b.ptr = new_ptr;
62  b.dim = new_size;
63  }
64 }
65 
66 void
68 {
69  // no deallocation
70 }
void * parser_alloc(const PARSER_CONTEXT *parser, const int length)
Definition: parse_tree.c:951
void alloc(cubmem::block &b, size_t size)
SP_PARSER_CTX * parser
#define NULL
Definition: freelistheap.h:34
void dealloc(cubmem::block &b)
parser_context * m_parser
parser_block_allocator()=delete