changeset 8660:f274fbc29747

chunked buffer allocation for pointers
author Jaroslav Hajek <highegg@gmail.com>
date Wed, 04 Feb 2009 10:18:22 +0100
parents 9792c26bffc7
children 9c092b111b1d
files liboctave/ChangeLog liboctave/oct-locbuf.h
diffstat 2 files changed, 22 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/ChangeLog	Wed Feb 04 10:18:20 2009 +0100
+++ b/liboctave/ChangeLog	Wed Feb 04 10:18:22 2009 +0100
@@ -1,3 +1,8 @@
+2009-02-04  Jaroslav Hajek  <highegg@gmail.com>
+
+	* oct-locbuf.h: Specialize OCTAVE_LOCAL_BUFFER to use chunked
+	allocation for pointers and const pointers.
+
 2009-02-03  Benjamin Lindner  <lindnerben@gmx.net>
 	
 	* Makefile.in: Add missing library reference.
--- a/liboctave/oct-locbuf.h	Wed Feb 04 10:18:20 2009 +0100
+++ b/liboctave/oct-locbuf.h	Wed Feb 04 10:18:22 2009 +0100
@@ -102,6 +102,23 @@
 SPECIALIZE_POD_BUFFER (FloatComplex);
 // MORE ?
 
+// All pointers and const pointers are also POD types.
+template <class T>
+class octave_local_buffer<T *> : private octave_chunk_buffer
+{
+public:
+  octave_local_buffer (size_t size) : octave_chunk_buffer (size * sizeof (T *)) { }
+  operator T **() const { return reinterpret_cast<T **> (this->data ()); }
+};
+
+template <class T>
+class octave_local_buffer<const T *> : private octave_chunk_buffer
+{
+public:
+  octave_local_buffer (size_t size) : octave_chunk_buffer (size * sizeof (const T *)) { }
+  operator const T **() const { return reinterpret_cast<const T **> (this->data ()); }
+};
+
 // If the compiler supports dynamic stack arrays, we can use the attached hack
 // to place small buffer arrays on the stack. It may be even faster than our
 // obstack-like optimization, but is dangerous because stack is a very limited