2 Copyright (c) 2004-2007 MySQL AB, 2009 Sun Microsystems, Inc.
3 Use is subject to license terms.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; version 2 of the License.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 #if defined(__GNUC__) && defined(USE_PRAGMA_IMPLEMENTATION)
20 #pragma implementation
26 const uint
Buffer::BUFFER_INITIAL_SIZE
= 4096;
27 const uint
Buffer::MAX_BUFFER_SIZE
= 16777216;
30 Puts the given string to the buffer.
34 position start position in the buffer
35 string string to be put in the buffer
36 len_arg the length of the string. This way we can avoid some
41 The method puts a string into the buffer, starting from position .
42 In the case when the buffer is too small it reallocs the buffer. The
43 total size of the buffer is restricted with 16.
47 1 - got an error in reserve()
50 int Buffer::append(size_t position
, const char *string
, size_t len_arg
)
52 if (reserve(position
, len_arg
))
55 strnmov((char*) buffer
+ position
, string
, len_arg
);
61 Checks whether the current buffer size is ok to put a string of the length
62 "len_arg" starting from "position" and reallocs it if no.
66 position the number starting byte on the buffer to store a buffer
67 len_arg the length of the string.
71 The method checks whether it is possible to put a string of the "len_arg"
72 length into the buffer, starting from "position" byte. In the case when the
73 buffer is too small it reallocs the buffer. The total size of the buffer is
74 restricted with 16 Mb.
78 1 - realloc error or we have come to the 16Mb barrier
81 int Buffer::reserve(size_t position
, size_t len_arg
)
83 if (position
+ len_arg
>= MAX_BUFFER_SIZE
)
86 if (position
+ len_arg
>= buffer_size
)
88 buffer
= (uchar
*) my_realloc(buffer
,
90 max((uint
) (buffer_size
*1.5),
91 position
+ len_arg
)), MYF(0));
94 buffer_size
= (size_t) (buffer_size
*1.5);
104 int Buffer::get_size()
106 return (uint
) buffer_size
;
110 int Buffer::is_error()