~stewart/drizzle/embedded-innodb-create-select-transaction-arrgh

« back to all changes in this revision

Viewing changes to storage/innobase/include/dyn0dyn.h

  • Committer: brian
  • Date: 2008-06-25 05:29:13 UTC
  • Revision ID: brian@localhost.localdomain-20080625052913-6upwo0jsrl4lnapl
clean slate

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/******************************************************
 
2
The dynamically allocated array
 
3
 
 
4
(c) 1996 Innobase Oy
 
5
 
 
6
Created 2/5/1996 Heikki Tuuri
 
7
*******************************************************/
 
8
 
 
9
#ifndef dyn0dyn_h
 
10
#define dyn0dyn_h
 
11
 
 
12
#include "univ.i"
 
13
#include "ut0lst.h"
 
14
#include "mem0mem.h"
 
15
 
 
16
typedef struct dyn_block_struct         dyn_block_t;
 
17
typedef dyn_block_t                     dyn_array_t;
 
18
 
 
19
 
 
20
/* This is the initial 'payload' size of a dynamic array;
 
21
this must be > MLOG_BUF_MARGIN + 30! */
 
22
#define DYN_ARRAY_DATA_SIZE     512
 
23
 
 
24
/*************************************************************************
 
25
Initializes a dynamic array. */
 
26
UNIV_INLINE
 
27
dyn_array_t*
 
28
dyn_array_create(
 
29
/*=============*/
 
30
                                /* out: initialized dyn array */
 
31
        dyn_array_t*    arr);   /* in: pointer to a memory buffer of
 
32
                                size sizeof(dyn_array_t) */
 
33
/****************************************************************
 
34
Frees a dynamic array. */
 
35
UNIV_INLINE
 
36
void
 
37
dyn_array_free(
 
38
/*===========*/
 
39
        dyn_array_t*    arr);   /* in: dyn array */
 
40
/*************************************************************************
 
41
Makes room on top of a dyn array and returns a pointer to a buffer in it.
 
42
After copying the elements, the caller must close the buffer using
 
43
dyn_array_close. */
 
44
UNIV_INLINE
 
45
byte*
 
46
dyn_array_open(
 
47
/*===========*/
 
48
                                /* out: pointer to the buffer */
 
49
        dyn_array_t*    arr,    /* in: dynamic array */
 
50
        ulint           size);  /* in: size in bytes of the buffer; MUST be
 
51
                                smaller than DYN_ARRAY_DATA_SIZE! */
 
52
/*************************************************************************
 
53
Closes the buffer returned by dyn_array_open. */
 
54
UNIV_INLINE
 
55
void
 
56
dyn_array_close(
 
57
/*============*/
 
58
        dyn_array_t*    arr,    /* in: dynamic array */
 
59
        byte*           ptr);   /* in: buffer space from ptr up was not used */
 
60
/*************************************************************************
 
61
Makes room on top of a dyn array and returns a pointer to
 
62
the added element. The caller must copy the element to
 
63
the pointer returned. */
 
64
UNIV_INLINE
 
65
void*
 
66
dyn_array_push(
 
67
/*===========*/
 
68
                                /* out: pointer to the element */
 
69
        dyn_array_t*    arr,    /* in: dynamic array */
 
70
        ulint           size);  /* in: size in bytes of the element */
 
71
/****************************************************************
 
72
Returns pointer to an element in dyn array. */
 
73
UNIV_INLINE
 
74
void*
 
75
dyn_array_get_element(
 
76
/*==================*/
 
77
                                /* out: pointer to element */
 
78
        dyn_array_t*    arr,    /* in: dyn array */
 
79
        ulint           pos);   /* in: position of element as bytes
 
80
                                from array start */
 
81
/****************************************************************
 
82
Returns the size of stored data in a dyn array. */
 
83
UNIV_INLINE
 
84
ulint
 
85
dyn_array_get_data_size(
 
86
/*====================*/
 
87
                                /* out: data size in bytes */
 
88
        dyn_array_t*    arr);   /* in: dyn array */
 
89
/****************************************************************
 
90
Gets the first block in a dyn array. */
 
91
UNIV_INLINE
 
92
dyn_block_t*
 
93
dyn_array_get_first_block(
 
94
/*======================*/
 
95
        dyn_array_t*    arr);   /* in: dyn array */
 
96
/****************************************************************
 
97
Gets the last block in a dyn array. */
 
98
UNIV_INLINE
 
99
dyn_block_t*
 
100
dyn_array_get_last_block(
 
101
/*=====================*/
 
102
        dyn_array_t*    arr);   /* in: dyn array */
 
103
/************************************************************************
 
104
Gets the next block in a dyn array. */
 
105
UNIV_INLINE
 
106
dyn_block_t*
 
107
dyn_array_get_next_block(
 
108
/*=====================*/
 
109
                                /* out: pointer to next, NULL if end of list */
 
110
        dyn_array_t*    arr,    /* in: dyn array */
 
111
        dyn_block_t*    block); /* in: dyn array block */
 
112
/************************************************************************
 
113
Gets the number of used bytes in a dyn array block. */
 
114
UNIV_INLINE
 
115
ulint
 
116
dyn_block_get_used(
 
117
/*===============*/
 
118
                                /* out: number of bytes used */
 
119
        dyn_block_t*    block); /* in: dyn array block */
 
120
/************************************************************************
 
121
Gets pointer to the start of data in a dyn array block. */
 
122
UNIV_INLINE
 
123
byte*
 
124
dyn_block_get_data(
 
125
/*===============*/
 
126
                                /* out: pointer to data */
 
127
        dyn_block_t*    block); /* in: dyn array block */
 
128
/************************************************************
 
129
Pushes n bytes to a dyn array. */
 
130
UNIV_INLINE
 
131
void
 
132
dyn_push_string(
 
133
/*============*/
 
134
        dyn_array_t*    arr,    /* in: dyn array */
 
135
        const byte*     str,    /* in: string to write */
 
136
        ulint           len);   /* in: string length */
 
137
 
 
138
/*#################################################################*/
 
139
 
 
140
/* NOTE! Do not use the fields of the struct directly: the definition
 
141
appears here only for the compiler to know its size! */
 
142
struct dyn_block_struct{
 
143
        mem_heap_t*     heap;   /* in the first block this is != NULL
 
144
                                if dynamic allocation has been needed */
 
145
        ulint           used;   /* number of data bytes used in this block */
 
146
        byte            data[DYN_ARRAY_DATA_SIZE];
 
147
                                /* storage for array elements */
 
148
        UT_LIST_BASE_NODE_T(dyn_block_t) base;
 
149
                                /* linear list of dyn blocks: this node is
 
150
                                used only in the first block */
 
151
        UT_LIST_NODE_T(dyn_block_t) list;
 
152
                                /* linear list node: used in all blocks */
 
153
#ifdef UNIV_DEBUG
 
154
        ulint           buf_end;/* only in the debug version: if dyn array is
 
155
                                opened, this is the buffer end offset, else
 
156
                                this is 0 */
 
157
        ulint           magic_n;
 
158
#endif
 
159
};
 
160
 
 
161
 
 
162
#ifndef UNIV_NONINL
 
163
#include "dyn0dyn.ic"
 
164
#endif
 
165
 
 
166
#endif