2
Copyright (C) 2003, 2005, 2006 MySQL AB
3
All rights reserved. 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
22
#include "ndbd_malloc.hpp"
25
* Template class used for implementing an c - array
34
* Set the size of the pool
36
* Note, can currently only be called once
38
bool setSize(Uint32 noOfElements, bool exit_on_error = true);
43
Uint32 getSize() const;
46
* Update p value for ptr according to i value
48
void getPtr(Ptr<T> &) const;
51
* Get pointer for i value
53
T * getPtr(Uint32 i) const;
56
* Update p & i value for ptr according to <b>i</b> value
58
void getPtr(Ptr<T> &, Uint32 i) const;
76
ndbd_free(theArray, size * sizeof(T));
82
* Set the size of the pool
84
* Note, can currently only be called once
89
CArray<T>::setSize(Uint32 noOfElements, bool exit_on_error){
90
if(size == noOfElements)
93
theArray = (T *)ndbd_malloc(noOfElements * sizeof(T));
98
ErrorReporter::handleAssert("CArray<T>::setSize malloc failed",
99
__FILE__, __LINE__, NDBD_EXIT_MEMALLOC);
100
return false; // not reached
109
CArray<T>::getSize() const {
116
CArray<T>::getPtr(Ptr<T> & ptr) const {
117
const Uint32 i = ptr.i;
119
ptr.p = &theArray[i];
122
ErrorReporter::handleAssert("CArray<T>::getPtr", __FILE__, __LINE__);
129
CArray<T>::getPtr(Uint32 i) const {
133
ErrorReporter::handleAssert("CArray<T>::getPtr", __FILE__, __LINE__);
141
CArray<T>::getPtr(Ptr<T> & ptr, Uint32 i) const {
144
ptr.p = &theArray[i];
147
ErrorReporter::handleAssert("CArray<T>::getPtr", __FILE__, __LINE__);