Mercurial > octave-nkf
annotate liboctave/util/oct-locbuf.h @ 20651:e54ecb33727e
lo-array-gripes.cc: Remove FIXME's related to buffer size.
* lo-array-gripes.cc: Remove FIXME's related to buffer size. Shorten sprintf
buffers from 100 to 64 characters (still well more than 19 required).
Use 'const' decorator on constant value for clarity. Remove extra space
between variable and array bracket.
author | Rik <rik@octave.org> |
---|---|
date | Mon, 12 Oct 2015 21:13:47 -0700 |
parents | 4197fc428c7d |
children |
rev | line source |
---|---|
8377 | 1 /* |
2 | |
19731
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
17822
diff
changeset
|
3 Copyright (C) 2008-2015 Jaroslav Hajek |
8377 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
9 Free Software Foundation; either version 3 of the License, or (at your | |
10 option) any later version. | |
11 | |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
18 along with Octave; see the file COPYING. If not, see | |
19 <http://www.gnu.org/licenses/>. | |
20 | |
21 */ | |
22 | |
17822
ebb3ef964372
maint: Use common #define syntax "octave_filename_h" in h_files.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
23 #if !defined (octave_oct_locbuf_h) |
ebb3ef964372
maint: Use common #define syntax "octave_filename_h" in h_files.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
24 #define octave_oct_locbuf_h 1 |
8377 | 25 |
26 #include <cstddef> | |
8400
7b6e1fc1cb90
implement obstack-like optimization of local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8379
diff
changeset
|
27 #include "oct-cmplx.h" |
8377 | 28 |
13981
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
29 // The default local buffer simply encapsulates an *array* pointer |
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
30 // that gets deleted automatically. For common POD types, we provide |
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
31 // specializations. |
8377 | 32 |
33 template <class T> | |
34 class octave_local_buffer | |
35 { | |
36 public: | |
37 octave_local_buffer (size_t size) | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
38 : data (0) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
39 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
40 if (size) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
41 data = new T [size]; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
42 } |
8377 | 43 ~octave_local_buffer (void) { delete [] data; } |
44 operator T *() const { return data; } | |
11506
964b7fd379f1
more constructor/destructor fixes
John W. Eaton <jwe@octave.org>
parents:
9237
diff
changeset
|
45 |
8377 | 46 private: |
47 T *data; | |
11506
964b7fd379f1
more constructor/destructor fixes
John W. Eaton <jwe@octave.org>
parents:
9237
diff
changeset
|
48 |
964b7fd379f1
more constructor/destructor fixes
John W. Eaton <jwe@octave.org>
parents:
9237
diff
changeset
|
49 // No copying! |
964b7fd379f1
more constructor/destructor fixes
John W. Eaton <jwe@octave.org>
parents:
9237
diff
changeset
|
50 octave_local_buffer (const octave_local_buffer&); |
964b7fd379f1
more constructor/destructor fixes
John W. Eaton <jwe@octave.org>
parents:
9237
diff
changeset
|
51 octave_local_buffer& operator = (const octave_local_buffer&); |
8377 | 52 }; |
53 | |
13981
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
54 // For buffers of POD types, we'll be smarter. There is one thing |
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
55 // that differentiates a local buffer from a dynamic array - the local |
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
56 // buffers, if not manipulated improperly, have a FIFO semantics, |
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
57 // meaning that if buffer B is allocated after buffer A, B *must* be |
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
58 // deallocated before A. This is *guaranteed* if you use local buffer |
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
59 // exclusively through the OCTAVE_LOCAL_BUFFER macro, because the C++ |
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
60 // standard requires that explicit local objects be destroyed in |
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
61 // reverse order of declaration. Therefore, we can avoid memory |
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
62 // fragmentation by allocating fairly large chunks of memory and |
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
63 // serving local buffers from them in a stack-like manner. The first |
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
64 // returning buffer in previous chunk will be responsible for |
8400
7b6e1fc1cb90
implement obstack-like optimization of local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8379
diff
changeset
|
65 // deallocating the chunk. |
8377 | 66 |
8400
7b6e1fc1cb90
implement obstack-like optimization of local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8379
diff
changeset
|
67 class octave_chunk_buffer |
7b6e1fc1cb90
implement obstack-like optimization of local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8379
diff
changeset
|
68 { |
11506
964b7fd379f1
more constructor/destructor fixes
John W. Eaton <jwe@octave.org>
parents:
9237
diff
changeset
|
69 public: |
964b7fd379f1
more constructor/destructor fixes
John W. Eaton <jwe@octave.org>
parents:
9237
diff
changeset
|
70 |
964b7fd379f1
more constructor/destructor fixes
John W. Eaton <jwe@octave.org>
parents:
9237
diff
changeset
|
71 OCTAVE_API octave_chunk_buffer (size_t size); |
964b7fd379f1
more constructor/destructor fixes
John W. Eaton <jwe@octave.org>
parents:
9237
diff
changeset
|
72 |
964b7fd379f1
more constructor/destructor fixes
John W. Eaton <jwe@octave.org>
parents:
9237
diff
changeset
|
73 OCTAVE_API virtual ~octave_chunk_buffer (void); |
964b7fd379f1
more constructor/destructor fixes
John W. Eaton <jwe@octave.org>
parents:
9237
diff
changeset
|
74 |
964b7fd379f1
more constructor/destructor fixes
John W. Eaton <jwe@octave.org>
parents:
9237
diff
changeset
|
75 char *data (void) const { return dat; } |
964b7fd379f1
more constructor/destructor fixes
John W. Eaton <jwe@octave.org>
parents:
9237
diff
changeset
|
76 |
13989
b4d399c975de
Export new added functions/classes (Woe32)
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13981
diff
changeset
|
77 static OCTAVE_API void clear (void); |
13981
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
78 |
11506
964b7fd379f1
more constructor/destructor fixes
John W. Eaton <jwe@octave.org>
parents:
9237
diff
changeset
|
79 private: |
13981
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
80 |
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
81 // The number of bytes we allocate for each large chunk of memory we |
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
82 // manage. |
8400
7b6e1fc1cb90
implement obstack-like optimization of local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8379
diff
changeset
|
83 static const size_t chunk_size; |
7b6e1fc1cb90
implement obstack-like optimization of local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8379
diff
changeset
|
84 |
13981
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
85 // Pointer to the end end of the last allocation. |
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
86 static char *top; |
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
87 |
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
88 // Pointer to the current active chunk. |
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
89 static char *chunk; |
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
90 |
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
91 // The number of bytes remaining in the active chunk. |
8400
7b6e1fc1cb90
implement obstack-like optimization of local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8379
diff
changeset
|
92 static size_t left; |
7b6e1fc1cb90
implement obstack-like optimization of local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8379
diff
changeset
|
93 |
13981
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
94 // The number of active allocations. |
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
95 static size_t active; |
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
96 |
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
97 // Pointer to the current chunk. |
8400
7b6e1fc1cb90
implement obstack-like optimization of local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8379
diff
changeset
|
98 char *cnk; |
13981
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
99 |
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
100 // Pointer to the beginning of the most recent allocation. |
8400
7b6e1fc1cb90
implement obstack-like optimization of local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8379
diff
changeset
|
101 char *dat; |
7b6e1fc1cb90
implement obstack-like optimization of local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8379
diff
changeset
|
102 |
11506
964b7fd379f1
more constructor/destructor fixes
John W. Eaton <jwe@octave.org>
parents:
9237
diff
changeset
|
103 // No copying! |
964b7fd379f1
more constructor/destructor fixes
John W. Eaton <jwe@octave.org>
parents:
9237
diff
changeset
|
104 octave_chunk_buffer (const octave_chunk_buffer&); |
964b7fd379f1
more constructor/destructor fixes
John W. Eaton <jwe@octave.org>
parents:
9237
diff
changeset
|
105 octave_chunk_buffer& operator = (const octave_chunk_buffer&); |
8400
7b6e1fc1cb90
implement obstack-like optimization of local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8379
diff
changeset
|
106 }; |
8377 | 107 |
13981
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
108 // This specializes octave_local_buffer to use the chunked buffer |
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
109 // mechanism for POD types. |
8400
7b6e1fc1cb90
implement obstack-like optimization of local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8379
diff
changeset
|
110 #define SPECIALIZE_POD_BUFFER(TYPE) \ |
7b6e1fc1cb90
implement obstack-like optimization of local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8379
diff
changeset
|
111 template <> \ |
7b6e1fc1cb90
implement obstack-like optimization of local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8379
diff
changeset
|
112 class octave_local_buffer<TYPE> : private octave_chunk_buffer \ |
7b6e1fc1cb90
implement obstack-like optimization of local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8379
diff
changeset
|
113 { \ |
7b6e1fc1cb90
implement obstack-like optimization of local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8379
diff
changeset
|
114 public: \ |
11506
964b7fd379f1
more constructor/destructor fixes
John W. Eaton <jwe@octave.org>
parents:
9237
diff
changeset
|
115 octave_local_buffer (size_t size) \ |
964b7fd379f1
more constructor/destructor fixes
John W. Eaton <jwe@octave.org>
parents:
9237
diff
changeset
|
116 : octave_chunk_buffer (size * sizeof (TYPE)) { } \ |
964b7fd379f1
more constructor/destructor fixes
John W. Eaton <jwe@octave.org>
parents:
9237
diff
changeset
|
117 \ |
964b7fd379f1
more constructor/destructor fixes
John W. Eaton <jwe@octave.org>
parents:
9237
diff
changeset
|
118 operator TYPE *() const \ |
964b7fd379f1
more constructor/destructor fixes
John W. Eaton <jwe@octave.org>
parents:
9237
diff
changeset
|
119 { \ |
964b7fd379f1
more constructor/destructor fixes
John W. Eaton <jwe@octave.org>
parents:
9237
diff
changeset
|
120 return reinterpret_cast<TYPE *> (this->data ()); \ |
964b7fd379f1
more constructor/destructor fixes
John W. Eaton <jwe@octave.org>
parents:
9237
diff
changeset
|
121 } \ |
8400
7b6e1fc1cb90
implement obstack-like optimization of local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8379
diff
changeset
|
122 } |
7b6e1fc1cb90
implement obstack-like optimization of local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8379
diff
changeset
|
123 |
7b6e1fc1cb90
implement obstack-like optimization of local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8379
diff
changeset
|
124 SPECIALIZE_POD_BUFFER (bool); |
7b6e1fc1cb90
implement obstack-like optimization of local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8379
diff
changeset
|
125 SPECIALIZE_POD_BUFFER (char); |
7b6e1fc1cb90
implement obstack-like optimization of local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8379
diff
changeset
|
126 SPECIALIZE_POD_BUFFER (unsigned short); |
7b6e1fc1cb90
implement obstack-like optimization of local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8379
diff
changeset
|
127 SPECIALIZE_POD_BUFFER (short); |
7b6e1fc1cb90
implement obstack-like optimization of local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8379
diff
changeset
|
128 SPECIALIZE_POD_BUFFER (int); |
7b6e1fc1cb90
implement obstack-like optimization of local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8379
diff
changeset
|
129 SPECIALIZE_POD_BUFFER (unsigned int); |
7b6e1fc1cb90
implement obstack-like optimization of local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8379
diff
changeset
|
130 SPECIALIZE_POD_BUFFER (long); |
7b6e1fc1cb90
implement obstack-like optimization of local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8379
diff
changeset
|
131 SPECIALIZE_POD_BUFFER (unsigned long); |
7b6e1fc1cb90
implement obstack-like optimization of local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8379
diff
changeset
|
132 SPECIALIZE_POD_BUFFER (float); |
7b6e1fc1cb90
implement obstack-like optimization of local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8379
diff
changeset
|
133 SPECIALIZE_POD_BUFFER (double); |
7b6e1fc1cb90
implement obstack-like optimization of local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8379
diff
changeset
|
134 // FIXME: Are these guaranteed to be POD and satisfy alignment? |
7b6e1fc1cb90
implement obstack-like optimization of local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8379
diff
changeset
|
135 SPECIALIZE_POD_BUFFER (Complex); |
7b6e1fc1cb90
implement obstack-like optimization of local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8379
diff
changeset
|
136 SPECIALIZE_POD_BUFFER (FloatComplex); |
7b6e1fc1cb90
implement obstack-like optimization of local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8379
diff
changeset
|
137 // MORE ? |
7b6e1fc1cb90
implement obstack-like optimization of local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8379
diff
changeset
|
138 |
8660
f274fbc29747
chunked buffer allocation for pointers
Jaroslav Hajek <highegg@gmail.com>
parents:
8400
diff
changeset
|
139 // All pointers and const pointers are also POD types. |
f274fbc29747
chunked buffer allocation for pointers
Jaroslav Hajek <highegg@gmail.com>
parents:
8400
diff
changeset
|
140 template <class T> |
f274fbc29747
chunked buffer allocation for pointers
Jaroslav Hajek <highegg@gmail.com>
parents:
8400
diff
changeset
|
141 class octave_local_buffer<T *> : private octave_chunk_buffer |
f274fbc29747
chunked buffer allocation for pointers
Jaroslav Hajek <highegg@gmail.com>
parents:
8400
diff
changeset
|
142 { |
f274fbc29747
chunked buffer allocation for pointers
Jaroslav Hajek <highegg@gmail.com>
parents:
8400
diff
changeset
|
143 public: |
11506
964b7fd379f1
more constructor/destructor fixes
John W. Eaton <jwe@octave.org>
parents:
9237
diff
changeset
|
144 octave_local_buffer (size_t size) |
964b7fd379f1
more constructor/destructor fixes
John W. Eaton <jwe@octave.org>
parents:
9237
diff
changeset
|
145 : octave_chunk_buffer (size * sizeof (T *)) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
146 { } |
11506
964b7fd379f1
more constructor/destructor fixes
John W. Eaton <jwe@octave.org>
parents:
9237
diff
changeset
|
147 |
8660
f274fbc29747
chunked buffer allocation for pointers
Jaroslav Hajek <highegg@gmail.com>
parents:
8400
diff
changeset
|
148 operator T **() const { return reinterpret_cast<T **> (this->data ()); } |
f274fbc29747
chunked buffer allocation for pointers
Jaroslav Hajek <highegg@gmail.com>
parents:
8400
diff
changeset
|
149 }; |
f274fbc29747
chunked buffer allocation for pointers
Jaroslav Hajek <highegg@gmail.com>
parents:
8400
diff
changeset
|
150 |
f274fbc29747
chunked buffer allocation for pointers
Jaroslav Hajek <highegg@gmail.com>
parents:
8400
diff
changeset
|
151 template <class T> |
f274fbc29747
chunked buffer allocation for pointers
Jaroslav Hajek <highegg@gmail.com>
parents:
8400
diff
changeset
|
152 class octave_local_buffer<const T *> : private octave_chunk_buffer |
f274fbc29747
chunked buffer allocation for pointers
Jaroslav Hajek <highegg@gmail.com>
parents:
8400
diff
changeset
|
153 { |
f274fbc29747
chunked buffer allocation for pointers
Jaroslav Hajek <highegg@gmail.com>
parents:
8400
diff
changeset
|
154 public: |
11506
964b7fd379f1
more constructor/destructor fixes
John W. Eaton <jwe@octave.org>
parents:
9237
diff
changeset
|
155 octave_local_buffer (size_t size) |
964b7fd379f1
more constructor/destructor fixes
John W. Eaton <jwe@octave.org>
parents:
9237
diff
changeset
|
156 : octave_chunk_buffer (size * sizeof (const T *)) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
157 { } |
11506
964b7fd379f1
more constructor/destructor fixes
John W. Eaton <jwe@octave.org>
parents:
9237
diff
changeset
|
158 |
964b7fd379f1
more constructor/destructor fixes
John W. Eaton <jwe@octave.org>
parents:
9237
diff
changeset
|
159 operator const T **() const |
964b7fd379f1
more constructor/destructor fixes
John W. Eaton <jwe@octave.org>
parents:
9237
diff
changeset
|
160 { |
964b7fd379f1
more constructor/destructor fixes
John W. Eaton <jwe@octave.org>
parents:
9237
diff
changeset
|
161 return reinterpret_cast<const T **> (this->data ()); |
964b7fd379f1
more constructor/destructor fixes
John W. Eaton <jwe@octave.org>
parents:
9237
diff
changeset
|
162 } |
8660
f274fbc29747
chunked buffer allocation for pointers
Jaroslav Hajek <highegg@gmail.com>
parents:
8400
diff
changeset
|
163 }; |
f274fbc29747
chunked buffer allocation for pointers
Jaroslav Hajek <highegg@gmail.com>
parents:
8400
diff
changeset
|
164 |
13981
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
165 // If the compiler supports dynamic stack arrays, we can use the |
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
166 // attached hack to place small buffer arrays on the stack. It may be |
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
167 // even faster than our obstack-like optimization, but is dangerous |
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
168 // because stack is a very limited resource, so we disable it. |
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
169 |
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
170 #if 0 // defined (HAVE_DYNAMIC_AUTO_ARRAYS) |
8377 | 171 |
172 // Maximum buffer size (in bytes) to be placed on the stack. | |
173 | |
174 #define OCTAVE_LOCAL_BUFFER_MAX_STACK_SIZE 8192 | |
175 | |
13981
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
176 // If we have automatic arrays, we use an automatic array if the size |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
177 // is small enough. To avoid possibly evaluating 'size' multiple |
13981
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
178 // times, we first cache it. Note that we always construct both the |
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
179 // stack array and the octave_local_buffer object, but only one of |
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
180 // them will be nonempty. |
8377 | 181 |
182 #define OCTAVE_LOCAL_BUFFER(T, buf, size) \ | |
183 const size_t _bufsize_ ## buf = size; \ | |
184 const bool _lbufaut_ ## buf = _bufsize_ ## buf * sizeof (T) \ | |
185 <= OCTAVE_LOCAL_BUFFER_MAX_STACK_SIZE; \ | |
186 T _bufaut_ ## buf [_lbufaut_ ## buf ? _bufsize_ ## buf : 0]; \ | |
13981
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
187 octave_local_buffer<T> _bufheap_ ## buf \ |
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
188 (!_lbufaut_ ## buf ? _bufsize_ ## buf : 0); \ |
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
189 T *buf = _lbufaut_ ## buf \ |
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
190 ? _bufaut_ ## buf : static_cast<T *> (_bufheap_ ## buf) |
8377 | 191 |
192 #else | |
193 | |
13981
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
194 // If we don't have automatic arrays, we simply always use |
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
195 // octave_local_buffer. |
8377 | 196 |
197 #define OCTAVE_LOCAL_BUFFER(T, buf, size) \ | |
198 octave_local_buffer<T> _buffer_ ## buf (size); \ | |
8379
ad8ed668e0a4
allow initialized local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8377
diff
changeset
|
199 T *buf = _buffer_ ## buf |
8377 | 200 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
201 #endif |
8377 | 202 |
13981
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
203 // Note: we use weird variables in the for loop to avoid warnings |
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
204 // about shadowed parameters. |
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
205 |
8379
ad8ed668e0a4
allow initialized local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8377
diff
changeset
|
206 #define OCTAVE_LOCAL_BUFFER_INIT(T, buf, size, value) \ |
15022
e47b4e8c2714
maint: Use space after OCTAVE_LOCAL_BUFFER invocation in liboctave source code.
Rik <rik@octave.org>
parents:
15020
diff
changeset
|
207 OCTAVE_LOCAL_BUFFER (T, buf, size); \ |
8379
ad8ed668e0a4
allow initialized local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8377
diff
changeset
|
208 for (size_t _buf_iter = 0, _buf_size = size; \ |
13981
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
209 _buf_iter < _buf_size; _buf_iter++) \ |
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
210 buf[_buf_iter] = value |
8379
ad8ed668e0a4
allow initialized local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8377
diff
changeset
|
211 |
8377 | 212 #endif |
213 |