drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
ut0vec.cc
1/*****************************************************************************
2
3Copyright (C) 2006, 2009, Innobase Oy. All Rights Reserved.
4
5This program is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License as published by the Free Software
7Foundation; version 2 of the License.
8
9This program is distributed in the hope that it will be useful, but WITHOUT
10ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
13You should have received a copy of the GNU General Public License along with
14this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
15St, Fifth Floor, Boston, MA 02110-1301 USA
16
17*****************************************************************************/
18
19/*******************************************************************/
25
26#include "ut0vec.h"
27#ifdef UNIV_NONINL
28#include "ut0vec.ic"
29#endif
30#include <string.h>
31
32/****************************************************************/
35UNIV_INTERN
38/*=============*/
39 mem_heap_t* heap,
40 ulint size)
41{
42 ut_a(size > 0);
43
44 ib_vector_t *vec = static_cast<ib_vector_t*>(mem_heap_alloc(heap, sizeof(*vec)));
45
46 vec->heap = heap;
47 vec->data = static_cast<void **>(mem_heap_alloc(heap, sizeof(void*) * size));
48 vec->used = 0;
49 vec->total = size;
50
51 return(vec);
52}
53
54/****************************************************************/
56UNIV_INTERN
57void
59/*===========*/
60 ib_vector_t* vec,
61 void* elem)
62{
63 if (vec->used >= vec->total) {
64 void** new_data;
65 ulint new_total = vec->total * 2;
66
67 new_data = static_cast<void **>(mem_heap_alloc(vec->heap,
68 sizeof(void*) * new_total));
69 memcpy(new_data, vec->data, sizeof(void*) * vec->total);
70
71 vec->data = static_cast<void **>(new_data);
72 vec->total = new_total;
73 }
74
75 vec->data[vec->used] = elem;
76 vec->used++;
77}
UNIV_INLINE void * mem_heap_alloc(mem_heap_t *heap, ulint n)
void ** data
Definition ut0vec.h:136
mem_heap_t * heap
Definition ut0vec.h:135
#define ut_a(EXPR)
Definition ut0dbg.h:105
UNIV_INTERN void ib_vector_push(ib_vector_t *vec, void *elem)
Definition ut0vec.cc:58
UNIV_INTERN ib_vector_t * ib_vector_create(mem_heap_t *heap, ulint size)
Definition ut0vec.cc:37
struct ib_vector_struct ib_vector_t
Definition ut0vec.h:34