Mercurial > octave
annotate liboctave/util/oct-locbuf.h @ 22197:e43d83253e28
refill multi-line macro definitions
Use the Emacs C++ mode style for line continuation markers in
multi-line macro definitions.
* make_int.cc, __dsearchn__.cc, __magick_read__.cc, besselj.cc,
bitfcns.cc, bsxfun.cc, cellfun.cc, data.cc, defun-dld.h, defun-int.h,
defun.h, det.cc, error.h, find.cc, gcd.cc, graphics.cc, interpreter.h,
jit-ir.h, jit-typeinfo.h, lookup.cc, ls-mat5.cc, max.cc, mexproto.h,
mxarray.in.h, oct-stream.cc, ordschur.cc, pr-output.cc, profiler.h,
psi.cc, regexp.cc, sparse-xdiv.cc, sparse-xpow.cc, tril.cc, txt-eng.h,
utils.cc, variables.cc, variables.h, xdiv.cc, xpow.cc, __glpk__.cc,
ov-base.cc, ov-base.h, ov-cell.cc, ov-ch-mat.cc, ov-classdef.cc,
ov-complex.cc, ov-cx-mat.cc, ov-cx-sparse.cc, ov-float.cc, ov-float.h,
ov-flt-complex.cc, ov-flt-cx-mat.cc, ov-flt-re-mat.cc,
ov-int-traits.h, ov-lazy-idx.h, ov-perm.cc, ov-re-mat.cc,
ov-re-sparse.cc, ov-scalar.cc, ov-scalar.h, ov-str-mat.cc,
ov-type-conv.h, ov.cc, ov.h, op-class.cc, op-int-conv.cc, op-int.h,
op-str-str.cc, ops.h, lex.ll, Array.cc, CMatrix.cc, CSparse.cc,
MArray.cc, MArray.h, MDiagArray2.cc, MDiagArray2.h, MSparse.h,
Sparse.cc, dMatrix.cc, dSparse.cc, fCMatrix.cc, fMatrix.cc,
idx-vector.cc, f77-fcn.h, quit.h, bsxfun-decl.h, bsxfun-defs.cc,
lo-specfun.cc, oct-convn.cc, oct-convn.h, oct-norm.cc, oct-norm.h,
oct-rand.cc, Sparse-op-decls.h, Sparse-op-defs.h, mx-inlines.cc,
mx-op-decl.h, mx-op-defs.h, mach-info.cc, oct-group.cc, oct-passwd.cc,
oct-syscalls.cc, oct-time.cc, data-conv.cc, kpse.cc, lo-ieee.h,
lo-macros.h, oct-cmplx.h, oct-glob.cc, oct-inttypes.cc,
oct-inttypes.h, oct-locbuf.h, oct-sparse.h, url-transfer.cc,
oct-conf-post.in.h, shared-fcns.h: Refill macro definitions.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 01 Aug 2016 12:40:18 -0400 |
parents | b571fc85953f |
children | bac0d6f07a3e |
rev | line source |
---|---|
8377 | 1 /* |
2 | |
19697
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 | |
20791
f7084eae3318
maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
23 #if ! defined (octave_oct_locbuf_h) |
17822
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 |
21244
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
21139
diff
changeset
|
26 #include "octave-config.h" |
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
21139
diff
changeset
|
27 |
8377 | 28 #include <cstddef> |
8400
7b6e1fc1cb90
implement obstack-like optimization of local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8379
diff
changeset
|
29 #include "oct-cmplx.h" |
8377 | 30 |
13981
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
31 // 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
|
32 // 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
|
33 // specializations. |
8377 | 34 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
35 template <typename T> |
8377 | 36 class octave_local_buffer |
37 { | |
38 public: | |
39 octave_local_buffer (size_t size) | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
40 : data (0) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
41 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
42 if (size) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
43 data = new T [size]; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
44 } |
21449
65e24ba4ca2d
* oct-locbuf.h: Style fix.
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
45 |
8377 | 46 ~octave_local_buffer (void) { delete [] data; } |
21449
65e24ba4ca2d
* oct-locbuf.h: Style fix.
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
47 |
8377 | 48 operator T *() const { return data; } |
11506
964b7fd379f1
more constructor/destructor fixes
John W. Eaton <jwe@octave.org>
parents:
9237
diff
changeset
|
49 |
8377 | 50 private: |
51 T *data; | |
11506
964b7fd379f1
more constructor/destructor fixes
John W. Eaton <jwe@octave.org>
parents:
9237
diff
changeset
|
52 |
964b7fd379f1
more constructor/destructor fixes
John W. Eaton <jwe@octave.org>
parents:
9237
diff
changeset
|
53 // No copying! |
964b7fd379f1
more constructor/destructor fixes
John W. Eaton <jwe@octave.org>
parents:
9237
diff
changeset
|
54 octave_local_buffer (const octave_local_buffer&); |
964b7fd379f1
more constructor/destructor fixes
John W. Eaton <jwe@octave.org>
parents:
9237
diff
changeset
|
55 octave_local_buffer& operator = (const octave_local_buffer&); |
8377 | 56 }; |
57 | |
13981
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
58 // 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
|
59 // 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
|
60 // 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
|
61 // 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
|
62 // 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
|
63 // 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
|
64 // 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
|
65 // 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
|
66 // 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
|
67 // 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
|
68 // 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
|
69 // deallocating the chunk. |
8377 | 70 |
8400
7b6e1fc1cb90
implement obstack-like optimization of local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8379
diff
changeset
|
71 class octave_chunk_buffer |
7b6e1fc1cb90
implement obstack-like optimization of local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8379
diff
changeset
|
72 { |
11506
964b7fd379f1
more constructor/destructor fixes
John W. Eaton <jwe@octave.org>
parents:
9237
diff
changeset
|
73 public: |
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 OCTAVE_API octave_chunk_buffer (size_t size); |
964b7fd379f1
more constructor/destructor fixes
John W. Eaton <jwe@octave.org>
parents:
9237
diff
changeset
|
76 |
964b7fd379f1
more constructor/destructor fixes
John W. Eaton <jwe@octave.org>
parents:
9237
diff
changeset
|
77 OCTAVE_API virtual ~octave_chunk_buffer (void); |
964b7fd379f1
more constructor/destructor fixes
John W. Eaton <jwe@octave.org>
parents:
9237
diff
changeset
|
78 |
964b7fd379f1
more constructor/destructor fixes
John W. Eaton <jwe@octave.org>
parents:
9237
diff
changeset
|
79 char *data (void) const { return dat; } |
964b7fd379f1
more constructor/destructor fixes
John W. Eaton <jwe@octave.org>
parents:
9237
diff
changeset
|
80 |
13989
b4d399c975de
Export new added functions/classes (Woe32)
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13981
diff
changeset
|
81 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
|
82 |
11506
964b7fd379f1
more constructor/destructor fixes
John W. Eaton <jwe@octave.org>
parents:
9237
diff
changeset
|
83 private: |
13981
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
84 |
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
85 // 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
|
86 // manage. |
8400
7b6e1fc1cb90
implement obstack-like optimization of local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8379
diff
changeset
|
87 static const size_t chunk_size; |
7b6e1fc1cb90
implement obstack-like optimization of local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8379
diff
changeset
|
88 |
13981
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
89 // 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
|
90 static char *top; |
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
91 |
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
92 // 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
|
93 static char *chunk; |
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
94 |
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
95 // 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
|
96 static size_t left; |
7b6e1fc1cb90
implement obstack-like optimization of local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8379
diff
changeset
|
97 |
13981
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
98 // The number of active allocations. |
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
99 static size_t active; |
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
100 |
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
101 // Pointer to the current chunk. |
8400
7b6e1fc1cb90
implement obstack-like optimization of local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8379
diff
changeset
|
102 char *cnk; |
13981
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
103 |
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
104 // 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
|
105 char *dat; |
7b6e1fc1cb90
implement obstack-like optimization of local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8379
diff
changeset
|
106 |
11506
964b7fd379f1
more constructor/destructor fixes
John W. Eaton <jwe@octave.org>
parents:
9237
diff
changeset
|
107 // No copying! |
964b7fd379f1
more constructor/destructor fixes
John W. Eaton <jwe@octave.org>
parents:
9237
diff
changeset
|
108 octave_chunk_buffer (const octave_chunk_buffer&); |
964b7fd379f1
more constructor/destructor fixes
John W. Eaton <jwe@octave.org>
parents:
9237
diff
changeset
|
109 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
|
110 }; |
8377 | 111 |
13981
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
112 // 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
|
113 // mechanism for POD types. |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
114 #define SPECIALIZE_POD_BUFFER(TYPE) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
115 template <> \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
116 class octave_local_buffer<TYPE> : private octave_chunk_buffer \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
117 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
118 public: \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
119 octave_local_buffer (size_t size) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
120 : octave_chunk_buffer (size * sizeof (TYPE)) { } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
121 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
122 operator TYPE *() const \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
123 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
124 return reinterpret_cast<TYPE *> (this->data ()); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
125 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
126 } |
8400
7b6e1fc1cb90
implement obstack-like optimization of local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8379
diff
changeset
|
127 |
7b6e1fc1cb90
implement obstack-like optimization of local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8379
diff
changeset
|
128 SPECIALIZE_POD_BUFFER (bool); |
7b6e1fc1cb90
implement obstack-like optimization of local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8379
diff
changeset
|
129 SPECIALIZE_POD_BUFFER (char); |
7b6e1fc1cb90
implement obstack-like optimization of local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8379
diff
changeset
|
130 SPECIALIZE_POD_BUFFER (unsigned short); |
7b6e1fc1cb90
implement obstack-like optimization of local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8379
diff
changeset
|
131 SPECIALIZE_POD_BUFFER (short); |
7b6e1fc1cb90
implement obstack-like optimization of local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8379
diff
changeset
|
132 SPECIALIZE_POD_BUFFER (int); |
7b6e1fc1cb90
implement obstack-like optimization of local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8379
diff
changeset
|
133 SPECIALIZE_POD_BUFFER (unsigned int); |
7b6e1fc1cb90
implement obstack-like optimization of local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8379
diff
changeset
|
134 SPECIALIZE_POD_BUFFER (long); |
7b6e1fc1cb90
implement obstack-like optimization of local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8379
diff
changeset
|
135 SPECIALIZE_POD_BUFFER (unsigned long); |
7b6e1fc1cb90
implement obstack-like optimization of local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8379
diff
changeset
|
136 SPECIALIZE_POD_BUFFER (float); |
7b6e1fc1cb90
implement obstack-like optimization of local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8379
diff
changeset
|
137 SPECIALIZE_POD_BUFFER (double); |
7b6e1fc1cb90
implement obstack-like optimization of local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8379
diff
changeset
|
138 // 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
|
139 SPECIALIZE_POD_BUFFER (Complex); |
7b6e1fc1cb90
implement obstack-like optimization of local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8379
diff
changeset
|
140 SPECIALIZE_POD_BUFFER (FloatComplex); |
7b6e1fc1cb90
implement obstack-like optimization of local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8379
diff
changeset
|
141 // MORE ? |
7b6e1fc1cb90
implement obstack-like optimization of local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8379
diff
changeset
|
142 |
8660
f274fbc29747
chunked buffer allocation for pointers
Jaroslav Hajek <highegg@gmail.com>
parents:
8400
diff
changeset
|
143 // All pointers and const pointers are also POD types. |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
144 template <typename T> |
8660
f274fbc29747
chunked buffer allocation for pointers
Jaroslav Hajek <highegg@gmail.com>
parents:
8400
diff
changeset
|
145 class octave_local_buffer<T *> : private octave_chunk_buffer |
f274fbc29747
chunked buffer allocation for pointers
Jaroslav Hajek <highegg@gmail.com>
parents:
8400
diff
changeset
|
146 { |
f274fbc29747
chunked buffer allocation for pointers
Jaroslav Hajek <highegg@gmail.com>
parents:
8400
diff
changeset
|
147 public: |
11506
964b7fd379f1
more constructor/destructor fixes
John W. Eaton <jwe@octave.org>
parents:
9237
diff
changeset
|
148 octave_local_buffer (size_t size) |
964b7fd379f1
more constructor/destructor fixes
John W. Eaton <jwe@octave.org>
parents:
9237
diff
changeset
|
149 : 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
|
150 { } |
11506
964b7fd379f1
more constructor/destructor fixes
John W. Eaton <jwe@octave.org>
parents:
9237
diff
changeset
|
151 |
8660
f274fbc29747
chunked buffer allocation for pointers
Jaroslav Hajek <highegg@gmail.com>
parents:
8400
diff
changeset
|
152 operator T **() const { return reinterpret_cast<T **> (this->data ()); } |
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 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
155 template <typename T> |
8660
f274fbc29747
chunked buffer allocation for pointers
Jaroslav Hajek <highegg@gmail.com>
parents:
8400
diff
changeset
|
156 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
|
157 { |
f274fbc29747
chunked buffer allocation for pointers
Jaroslav Hajek <highegg@gmail.com>
parents:
8400
diff
changeset
|
158 public: |
11506
964b7fd379f1
more constructor/destructor fixes
John W. Eaton <jwe@octave.org>
parents:
9237
diff
changeset
|
159 octave_local_buffer (size_t size) |
964b7fd379f1
more constructor/destructor fixes
John W. Eaton <jwe@octave.org>
parents:
9237
diff
changeset
|
160 : 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
|
161 { } |
11506
964b7fd379f1
more constructor/destructor fixes
John W. Eaton <jwe@octave.org>
parents:
9237
diff
changeset
|
162 |
964b7fd379f1
more constructor/destructor fixes
John W. Eaton <jwe@octave.org>
parents:
9237
diff
changeset
|
163 operator const T **() const |
964b7fd379f1
more constructor/destructor fixes
John W. Eaton <jwe@octave.org>
parents:
9237
diff
changeset
|
164 { |
964b7fd379f1
more constructor/destructor fixes
John W. Eaton <jwe@octave.org>
parents:
9237
diff
changeset
|
165 return reinterpret_cast<const T **> (this->data ()); |
964b7fd379f1
more constructor/destructor fixes
John W. Eaton <jwe@octave.org>
parents:
9237
diff
changeset
|
166 } |
8660
f274fbc29747
chunked buffer allocation for pointers
Jaroslav Hajek <highegg@gmail.com>
parents:
8400
diff
changeset
|
167 }; |
f274fbc29747
chunked buffer allocation for pointers
Jaroslav Hajek <highegg@gmail.com>
parents:
8400
diff
changeset
|
168 |
13981
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
169 // If the compiler supports dynamic stack arrays, we can use the |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21449
diff
changeset
|
170 // attached hack to place small buffer arrays on the stack. It may be |
13981
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
171 // 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
|
172 // 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
|
173 |
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
174 #if 0 // defined (HAVE_DYNAMIC_AUTO_ARRAYS) |
8377 | 175 |
176 // Maximum buffer size (in bytes) to be placed on the stack. | |
177 | |
178 #define OCTAVE_LOCAL_BUFFER_MAX_STACK_SIZE 8192 | |
179 | |
13981
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
180 // 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
|
181 // 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
|
182 // 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
|
183 // 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
|
184 // them will be nonempty. |
8377 | 185 |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
186 #define OCTAVE_LOCAL_BUFFER(T, buf, size) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
187 const size_t _bufsize_ ## buf = size; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
188 const bool _lbufaut_ ## buf = _bufsize_ ## buf * sizeof (T) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
189 <= OCTAVE_LOCAL_BUFFER_MAX_STACK_SIZE; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
190 T _bufaut_ ## buf [_lbufaut_ ## buf ? _bufsize_ ## buf : 0]; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
191 octave_local_buffer<T> _bufheap_ ## buf (! _lbufaut_ ## buf ? _bufsize_ ## buf : 0); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
192 T *buf = (_lbufaut_ ## buf \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
193 ? _bufaut_ ## buf : static_cast<T *> (_bufheap_ ## buf)) |
8377 | 194 |
195 #else | |
196 | |
13981
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
197 // 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
|
198 // octave_local_buffer. |
8377 | 199 |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
200 #define OCTAVE_LOCAL_BUFFER(T, buf, size) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
201 octave_local_buffer<T> _buffer_ ## buf (size); \ |
8379
ad8ed668e0a4
allow initialized local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8377
diff
changeset
|
202 T *buf = _buffer_ ## buf |
8377 | 203 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
204 #endif |
8377 | 205 |
13981
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
206 // 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
|
207 // about shadowed parameters. |
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
208 |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
209 #define OCTAVE_LOCAL_BUFFER_INIT(T, buf, size, value) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
210 OCTAVE_LOCAL_BUFFER (T, buf, size); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
211 for (size_t _buf_iter = 0, _buf_size = size; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
212 _buf_iter < _buf_size; _buf_iter++) \ |
13981
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
213 buf[_buf_iter] = value |
8379
ad8ed668e0a4
allow initialized local buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8377
diff
changeset
|
214 |
8377 | 215 #endif |
216 |