# HG changeset patch # User jwe # Date 847385296 0 # Node ID 3d905d3820a4e7de028c1a954a938bd43b1a883e # Parent 4de4cebed08851de626c06cc9b7354b372d7d2ee [project @ 1996-11-07 16:46:11 by jwe] diff -r 4de4cebed088 -r 3d905d3820a4 PROJECTS --- a/PROJECTS Thu Nov 07 05:16:55 1996 +0000 +++ b/PROJECTS Thu Nov 07 16:48:16 1996 +0000 @@ -45,6 +45,9 @@ * Move rand, eye, xpow, xdiv, etc., functions to the matrix classes. + * Use octave_allocator for memory management in Array classes once + g++ supports static member templates. + * Implement the following functions: -- ppval -- cross -- dot diff -r 4de4cebed088 -r 3d905d3820a4 liboctave/Array2.cc --- a/liboctave/Array2.cc Thu Nov 07 05:16:55 1996 +0000 +++ b/liboctave/Array2.cc Thu Nov 07 16:48:16 1996 +0000 @@ -119,6 +119,7 @@ ArrayRep *old_rep = rep; const T *old_data = data (); + int old_d1 = dim1 (); int old_d2 = dim2 (); int old_len = length (); diff -r 4de4cebed088 -r 3d905d3820a4 liboctave/Array3.cc --- a/liboctave/Array3.cc Thu Nov 07 05:16:55 1996 +0000 +++ b/liboctave/Array3.cc Thu Nov 07 16:48:16 1996 +0000 @@ -46,16 +46,109 @@ template void -Array3::resize (int n, int m, int k) +Array3::resize (int r, int c, int p) { - assert (0); // XXX FIXME XXX + if (r < 0 || c < 0 || p < 0) + { + (*current_liboctave_error_handler) + ("can't resize to negative dimension"); + return; + } + + if (r == dim1 () && c == dim2 () && p == dim3 ()) + return; + + ArrayRep *old_rep = rep; + const T *old_data = data (); + + int old_d1 = dim1 (); + int old_d2 = dim2 (); + int old_d3 = dim3 (); + int old_len = length (); + + rep = new ArrayRep (r*c*p); + + d1 = r; + d2 = c; + d3 = p; + + if (old_data && old_len > 0) + { + int min_r = old_d1 < r ? old_d1 : r; + int min_c = old_d2 < c ? old_d2 : c; + int min_p = old_d3 < p ? old_d3 : p; + + for (int k = 0; k < min_p; k++) + for (int j = 0; j < min_c; j++) + for (int i = 0; i < min_r; i++) + xelem (i, j, k) = old_data[old_d1*(old_d2*k+j)+i]; + } + + if (--old_rep->count <= 0) + delete old_rep; } template void Array3::resize (int n, int m, int k, const T& val) { - assert (0); // XXX FIXME XXX + if (r < 0 || c < 0 || p < 0) + { + (*current_liboctave_error_handler) + ("can't resize to negative dimension"); + return; + } + + if (r == dim1 () && c == dim2 () && p == dim3 ()) + return; + + ArrayRep *old_rep = rep; + const T *old_data = data (); + + int old_d1 = dim1 (); + int old_d2 = dim2 (); + int old_d3 = dim3 (); + int old_len = length (); + + rep = new ArrayRep (r*c*p); + + d1 = r; + d2 = c; + d3 = p; + + if (old_data && old_len > 0) + { + int min_r = old_d1 < r ? old_d1 : r; + int min_c = old_d2 < c ? old_d2 : c; + int min_p = old_d3 < p ? old_d3 : p; + + for (int k = 0; k < min_p; k++) + for (int j = 0; j < min_c; j++) + for (int i = 0; i < min_r; i++) + xelem (i, j, k) = old_data[old_d1*(old_d2*k+j)+i]; + } + + // If the copy constructor is expensive, this may win. Otherwise, + // it may make more sense to just copy the value everywhere when + // making the new ArrayRep. + + for (int k = 0; k < min_p; k++) + for (int j = min_c; j < c; j++) + for (int i = 0; i < min_r; i++) + xelem (i, j, k) = val; + + for (int k = 0; k < min_p; k++) + for (int j = 0; j < c; j++) + for (int i = min_r; i < r; i++) + xelem (i, j, k) = val; + + for (int k = min_p; k < p; k++) + for (int j = 0; j < c; j++) + for (int i = 0; i < r; i++) + xelem (i, j, k) = val; + + if (--old_rep->count <= 0) + delete old_rep; } /* diff -r 4de4cebed088 -r 3d905d3820a4 src/ChangeLog --- a/src/ChangeLog Thu Nov 07 05:16:55 1996 +0000 +++ b/src/ChangeLog Thu Nov 07 16:48:16 1996 +0000 @@ -1,3 +1,13 @@ +Thu Nov 7 07:59:07 1996 John W. Eaton + + * ov-struct.cc, ov-struct.h: Add hooks for custom memory management. + * ov-scalar.cc, ov-scalar.h: Likewise. + * ov-re-mat.cc, ov-re-mat.h: Likewise. + * ov-range.cc, ov-range.h: Likewise. + * ov-cx-mat.cc, ov-cx-mat.h: Likewise. + * ov-complex.cc, ov-complex.h: Likewise. + * ov-ch-mat.cc, ov-ch-mat.h: Likewise. + Wed Nov 6 12:32:48 1996 John W. Eaton * pager.cc (do_sync): Don't call clear_external_pager here. diff -r 4de4cebed088 -r 3d905d3820a4 src/ov-base.h --- a/src/ov-base.h Thu Nov 07 05:16:55 1996 +0000 +++ b/src/ov-base.h Thu Nov 07 16:48:16 1996 +0000 @@ -45,7 +45,9 @@ class tree_walker; -// Real scalar values. +// A base value type, so that derived types only have to redefine what +// they need (if they are derived from octave_base_value instead of +// octave_value). class octave_base_value : public octave_value @@ -62,11 +64,6 @@ octave_value *clone (void) { return new octave_base_value (*this); } -#if 0 - void *operator new (size_t size); - void operator delete (void *p, size_t size); -#endif - type_conv_fcn numeric_conversion_function (void) const { return (type_conv_fcn) 0; } @@ -182,8 +179,10 @@ private: + // Type id of base value objects, set by register_type(). static int t_id; + // Type name of base value objects, defined in ov-base.cc. static const string t_name; }; diff -r 4de4cebed088 -r 3d905d3820a4 src/ov-ch-mat.cc --- a/src/ov-ch-mat.cc Thu Nov 07 05:16:55 1996 +0000 +++ b/src/ov-ch-mat.cc Thu Nov 07 16:48:16 1996 +0000 @@ -35,9 +35,14 @@ #include "gripes.h" #include "pr-output.h" -int octave_char_matrix::t_id = -1; +octave_allocator +octave_char_matrix::allocator (sizeof (octave_char_matrix)); -const string octave_char_matrix::t_name ("char matrix"); +int +octave_char_matrix::t_id (-1); + +const string +octave_char_matrix::t_name ("char matrix"); bool octave_char_matrix::valid_as_scalar_index (void) const diff -r 4de4cebed088 -r 3d905d3820a4 src/ov-ch-mat.h --- a/src/ov-ch-mat.h Thu Nov 07 05:16:55 1996 +0000 +++ b/src/ov-ch-mat.h Thu Nov 07 16:48:16 1996 +0000 @@ -34,6 +34,7 @@ class ostream; #include "mx-base.h" +#include "oct-alloc.h" #include "str-vec.h" #include "error.h" @@ -45,7 +46,7 @@ class tree_walker; -// Real scalar values. +// Character matrix values. class octave_char_matrix : public octave_base_value @@ -74,10 +75,11 @@ octave_value *clone (void) { return new octave_char_matrix (*this); } -#if 0 - void *operator new (size_t size); - void operator delete (void *p, size_t size); -#endif + void *operator new (size_t size) + { return allocator.alloc (size); } + + void operator delete (void *p, size_t size) + { allocator.free (p, size); } int rows (void) const { return matrix.rows (); } int columns (void) const { return matrix.columns (); } @@ -129,8 +131,12 @@ charMatrix matrix; + static octave_allocator allocator; + + // Type id of character matrix objects, set by register_type(). static int t_id; + // Type name of character matrix objects, defined in ov-ch-mat.cc. static const string t_name; }; diff -r 4de4cebed088 -r 3d905d3820a4 src/ov-colon.h --- a/src/ov-colon.h Thu Nov 07 05:16:55 1996 +0000 +++ b/src/ov-colon.h Thu Nov 07 16:48:16 1996 +0000 @@ -41,7 +41,7 @@ class tree_walker; -// Real scalar values. +// A type to represent `:' as used for indexing. class octave_magic_colon : public octave_base_value @@ -58,11 +58,6 @@ octave_value *clone (void) { return new octave_magic_colon (*this); } -#if 0 - void *operator new (size_t size); - void operator delete (void *p, size_t size); -#endif - idx_vector index_vector (void) const { return idx_vector (':'); } bool is_defined (void) const { return true; } @@ -86,8 +81,10 @@ private: + // Type id of magic colon objects, set by register_type(). static int t_id; + // Type name of magic colon objects, defined in ov-colon.cc. static const string t_name; }; diff -r 4de4cebed088 -r 3d905d3820a4 src/ov-complex.cc --- a/src/ov-complex.cc Thu Nov 07 05:16:55 1996 +0000 +++ b/src/ov-complex.cc Thu Nov 07 16:48:16 1996 +0000 @@ -38,9 +38,14 @@ #include "gripes.h" #include "pr-output.h" -int octave_complex::t_id = -1; +octave_allocator +octave_complex::allocator (sizeof (octave_complex)); -const string octave_complex::t_name ("complex scalar"); +int +octave_complex::t_id (-1); + +const string +octave_complex::t_name ("complex scalar"); octave_value * octave_complex::try_narrowing_conversion (void) diff -r 4de4cebed088 -r 3d905d3820a4 src/ov-complex.h --- a/src/ov-complex.h Thu Nov 07 05:16:55 1996 +0000 +++ b/src/ov-complex.h Thu Nov 07 16:48:16 1996 +0000 @@ -34,6 +34,7 @@ class ostream; #include "mx-base.h" +#include "oct-alloc.h" #include "str-vec.h" #include "error.h" @@ -45,7 +46,7 @@ class tree_walker; -// Real scalar values. +// Complex scalar values. class octave_complex : public octave_base_value @@ -65,10 +66,11 @@ octave_value *clone (void) { return new octave_complex (*this); } -#if 0 - void *operator new (size_t size); - void operator delete (void *p, size_t size); -#endif + void *operator new (size_t size) + { return allocator.alloc (size); } + + void operator delete (void *p, size_t size) + { allocator.free (p, size); } octave_value *try_narrowing_conversion (void); @@ -133,8 +135,12 @@ Complex scalar; + static octave_allocator allocator; + + // Type id of complex scalar objects, set in register_type(). static int t_id; + // Type name of complex scalar objects, defined in ov-complex.cc. static const string t_name; }; diff -r 4de4cebed088 -r 3d905d3820a4 src/ov-cx-mat.cc --- a/src/ov-cx-mat.cc Thu Nov 07 05:16:55 1996 +0000 +++ b/src/ov-cx-mat.cc Thu Nov 07 16:48:16 1996 +0000 @@ -40,9 +40,14 @@ #include "ov-scalar.h" #include "pr-output.h" -int octave_complex_matrix::t_id = -1; +octave_allocator +octave_complex_matrix::allocator (sizeof (octave_complex_matrix)); -const string octave_complex_matrix::t_name ("complex matrix"); +int +octave_complex_matrix::t_id (-1); + +const string +octave_complex_matrix::t_name ("complex matrix"); octave_complex_matrix::octave_complex_matrix (const ComplexRowVector& v, int pcv) diff -r 4de4cebed088 -r 3d905d3820a4 src/ov-cx-mat.h --- a/src/ov-cx-mat.h Thu Nov 07 05:16:55 1996 +0000 +++ b/src/ov-cx-mat.h Thu Nov 07 16:48:16 1996 +0000 @@ -34,6 +34,7 @@ class ostream; #include "mx-base.h" +#include "oct-alloc.h" #include "str-vec.h" #include "error.h" @@ -45,7 +46,7 @@ class tree_walker; -// Real scalar values. +// Complex matrix values. class octave_complex_matrix : public octave_base_value @@ -72,10 +73,11 @@ octave_value *clone (void) { return new octave_complex_matrix (*this); } -#if 0 - void *operator new (size_t size); - void operator delete (void *p, size_t size); -#endif + void *operator new (size_t size) + { return allocator.alloc (size); } + + void operator delete (void *p, size_t size) + { allocator.free (p, size); } octave_value *try_narrowing_conversion (void); @@ -145,8 +147,12 @@ ComplexMatrix matrix; + static octave_allocator allocator; + + // Type id of complex matrix objects, set by register_type(). static int t_id; + // Type name of complex matrix objects, defined in ov-cx-mat.cc. static const string t_name; }; diff -r 4de4cebed088 -r 3d905d3820a4 src/ov-range.cc --- a/src/ov-range.cc Thu Nov 07 05:16:55 1996 +0000 +++ b/src/ov-range.cc Thu Nov 07 16:48:16 1996 +0000 @@ -38,9 +38,14 @@ #include "ov-scalar.h" #include "pr-output.h" -int octave_range::t_id = -1; +octave_allocator +octave_range::allocator (sizeof (octave_range)); -const string octave_range::t_name ("range"); +int +octave_range::t_id (-1); + +const string +octave_range::t_name ("range"); static octave_value * default_numeric_conversion_function (const octave_value& a) diff -r 4de4cebed088 -r 3d905d3820a4 src/ov-range.h --- a/src/ov-range.h Thu Nov 07 05:16:55 1996 +0000 +++ b/src/ov-range.h Thu Nov 07 16:48:16 1996 +0000 @@ -37,6 +37,7 @@ #include "lo-utils.h" #include "mx-base.h" +#include "oct-alloc.h" #include "str-vec.h" #include "error.h" @@ -80,10 +81,11 @@ octave_value *clone (void) { return new octave_range (*this); } -#if 0 - void *operator new (size_t size); - void operator delete (void *p, size_t size); -#endif + void *operator new (size_t size) + { return allocator.alloc (size); } + + void operator delete (void *p, size_t size) + { allocator.free (p, size); } type_conv_fcn numeric_conversion_function (void) const; @@ -156,8 +158,12 @@ Range range; + static octave_allocator allocator; + + // Type id of range objects, set by register_type (). static int t_id; + // Type name of scalar objects, defined in ov-range.cc. static const string t_name; }; diff -r 4de4cebed088 -r 3d905d3820a4 src/ov-re-mat.cc --- a/src/ov-re-mat.cc Thu Nov 07 05:16:55 1996 +0000 +++ b/src/ov-re-mat.cc Thu Nov 07 16:48:16 1996 +0000 @@ -40,9 +40,14 @@ #include "ov-re-mat.h" #include "pr-output.h" -int octave_matrix::t_id = -1; +octave_allocator +octave_matrix::allocator (sizeof (octave_matrix)); -const string octave_matrix::t_name ("matrix"); +int +octave_matrix::t_id (-1); + +const string +octave_matrix::t_name ("matrix"); octave_matrix::octave_matrix (const RowVector& v, int pcv) : octave_base_value (), diff -r 4de4cebed088 -r 3d905d3820a4 src/ov-re-mat.h --- a/src/ov-re-mat.h Thu Nov 07 05:16:55 1996 +0000 +++ b/src/ov-re-mat.h Thu Nov 07 16:48:16 1996 +0000 @@ -34,6 +34,7 @@ class ostream; #include "mx-base.h" +#include "oct-alloc.h" #include "str-vec.h" #include "error.h" @@ -72,10 +73,11 @@ octave_value *clone (void) { return new octave_matrix (*this); } -#if 0 - void *operator new (size_t size); - void operator delete (void *p, size_t size); -#endif + void *operator new (size_t size) + { return allocator.alloc (size); } + + void operator delete (void *p, size_t size) + { allocator.free (p, size); } octave_value *try_narrowing_conversion (void); @@ -146,8 +148,12 @@ Matrix matrix; + static octave_allocator allocator; + + // Type id of matrix objects, set by register_type (). static int t_id; + // Type name of matrix objects, defined in ov-re-mat.cc. static const string t_name; }; diff -r 4de4cebed088 -r 3d905d3820a4 src/ov-scalar.cc --- a/src/ov-scalar.cc Thu Nov 07 05:16:55 1996 +0000 +++ b/src/ov-scalar.cc Thu Nov 07 16:48:16 1996 +0000 @@ -38,9 +38,14 @@ #include "xdiv.h" #include "xpow.h" -int octave_scalar::t_id = -1; +octave_allocator +octave_scalar::allocator (sizeof (octave_scalar)); -const string octave_scalar::t_name ("scalar"); +int +octave_scalar::t_id (-1); + +const string +octave_scalar::t_name ("scalar"); static inline bool valid_scalar_indices (const octave_value_list& args) diff -r 4de4cebed088 -r 3d905d3820a4 src/ov-scalar.h --- a/src/ov-scalar.h Thu Nov 07 05:16:55 1996 +0000 +++ b/src/ov-scalar.h Thu Nov 07 16:48:16 1996 +0000 @@ -35,6 +35,7 @@ #include "lo-utils.h" #include "mx-base.h" +#include "oct-alloc.h" #include "str-vec.h" #include "mappers.h" @@ -66,10 +67,11 @@ octave_value *clone (void) { return new octave_scalar (*this); } -#if 0 - void *operator new (size_t size); - void operator delete (void *p, size_t size); -#endif + void *operator new (size_t size) + { return allocator.alloc (size); } + + void operator delete (void *p, size_t size) + { allocator.free (p, size); } octave_value index (const octave_value_list& idx) const; @@ -132,10 +134,16 @@ private: + // The value of this scalar. double scalar; + // For custom memory management. + static octave_allocator allocator; + + // Type id of scalar objects, set by register_type(). static int t_id; + // Type name of scalar objects, defined in ov-scalar.cc. static const string t_name; }; diff -r 4de4cebed088 -r 3d905d3820a4 src/ov-str-mat.h --- a/src/ov-str-mat.h Thu Nov 07 05:16:55 1996 +0000 +++ b/src/ov-str-mat.h Thu Nov 07 16:48:16 1996 +0000 @@ -45,7 +45,8 @@ class tree_walker; -// Real scalar values. +// Character matrix values with special properties for use as +// strings. class octave_char_matrix_str : public octave_char_matrix @@ -77,11 +78,6 @@ octave_value *clone (void) { return new octave_char_matrix_str (*this); } -#if 0 - void *operator new (size_t size); - void operator delete (void *p, size_t size); -#endif - type_conv_fcn numeric_conversion_function (void) const; octave_value index (const octave_value_list& idx) const; @@ -119,8 +115,10 @@ private: + // Type id of char_matrix_str objects, set by register_type(). static int t_id; + // Type name of char_matrix_strXX objects, defined in ov-str-mat.cc. static const string t_name; }; diff -r 4de4cebed088 -r 3d905d3820a4 src/ov-struct.cc --- a/src/ov-struct.cc Thu Nov 07 05:16:55 1996 +0000 +++ b/src/ov-struct.cc Thu Nov 07 16:48:16 1996 +0000 @@ -34,10 +34,14 @@ #include "ov-struct.h" #include "unwind-prot.h" -int octave_struct::t_id = -1; +octave_allocator +octave_struct::allocator (sizeof (octave_struct)); -const string octave_struct::t_name ("struct"); +int +octave_struct::t_id (-1); +const string +octave_struct::t_name ("struct"); octave_value octave_struct::struct_elt_val (const string& nm, bool silent) const diff -r 4de4cebed088 -r 3d905d3820a4 src/ov-struct.h --- a/src/ov-struct.h Thu Nov 07 05:16:55 1996 +0000 +++ b/src/ov-struct.h Thu Nov 07 16:48:16 1996 +0000 @@ -37,6 +37,7 @@ #include "str-vec.h" #include "error.h" +#include "oct-alloc.h" #include "oct-map.h" #include "ov-base.h" #include "ov-typeinfo.h" @@ -46,7 +47,7 @@ class tree_walker; -// Real scalar values. +// Data structures. class octave_struct : public octave_base_value @@ -66,10 +67,11 @@ octave_value *clone (void) { return new octave_struct (*this); } -#if 0 - void *operator new (size_t size); - void operator delete (void *p, size_t size); -#endif + void *operator new (size_t size) + { return allocator.alloc (size); } + + void operator delete (void *p, size_t size) + { allocator.free (p, size); } octave_value struct_elt_val (const string& nm, bool silent) const; @@ -94,10 +96,16 @@ private: + // The associative array used to manage the structure data. Octave_map map; + // For custom memory management. + static octave_allocator allocator; + + // Type id of struct objects, set by register_type(). static int t_id; + // Type name of struct objects, defined in ov-struct.cc. static const string t_name; }; diff -r 4de4cebed088 -r 3d905d3820a4 src/ov-va-args.h --- a/src/ov-va-args.h Thu Nov 07 05:16:55 1996 +0000 +++ b/src/ov-va-args.h Thu Nov 07 16:48:16 1996 +0000 @@ -41,7 +41,7 @@ class tree_walker; -// Real scalar values. +// A type to represent `all_va_args' as used in function calls. class octave_all_va_args : public octave_base_value @@ -58,11 +58,6 @@ octave_value *clone (void) { return new octave_all_va_args (*this); } -#if 0 - void *operator new (size_t size); - void operator delete (void *p, size_t size); -#endif - bool is_defined (void) const { return true; } bool is_all_va_args (void) const { return true; } @@ -80,8 +75,10 @@ private: + // Type id of all_va_arg objects, set by register_type(). static int t_id; + // Type name of all_va_arg objects, defined in ov-va-args.cc. static const string t_name; }; diff -r 4de4cebed088 -r 3d905d3820a4 src/ov.cc --- a/src/ov.cc Thu Nov 07 05:16:55 1996 +0000 +++ b/src/ov.cc Thu Nov 07 16:48:16 1996 +0000 @@ -51,6 +51,11 @@ #include "utils.h" #include "variables.h" +// We are likely to have a lot of octave_value objects to allocate, so +// make the grow_size large. +octave_allocator +octave_value::allocator (sizeof (octave_value), 1024); + // If TRUE, allow assignments like // // octave> A(1) = 3; A(2) = 5 diff -r 4de4cebed088 -r 3d905d3820a4 src/ov.h --- a/src/ov.h Thu Nov 07 05:16:55 1996 +0000 +++ b/src/ov.h Thu Nov 07 16:48:16 1996 +0000 @@ -38,6 +38,7 @@ #include "Range.h" #include "idx-vector.h" #include "mx-base.h" +#include "oct-alloc.h" #include "str-vec.h" #include "error.h" @@ -158,10 +159,11 @@ } } -#if 0 - void *operator new (size_t size); - void operator delete (void *p, size_t size); -#endif + void *operator new (size_t size) + { return allocator.alloc (size); } + + void operator delete (void *p, size_t size) + { allocator.free (p, size); } // Simple assignment. @@ -392,6 +394,8 @@ private: + static octave_allocator allocator; + union { octave_value *freeptr; // For custom memory management. diff -r 4de4cebed088 -r 3d905d3820a4 src/pt-const.cc --- a/src/pt-const.cc Thu Nov 07 05:16:55 1996 +0000 +++ b/src/pt-const.cc Thu Nov 07 16:48:16 1996 +0000 @@ -60,9 +60,10 @@ #include "utils.h" #include "variables.h" -// We are likely to have a lot of tree_constants to allocate, so make -// the grow_size large. -octave_allocator tree_constant::allocator (sizeof (tree_constant), 1024); +// We are likely to have a lot of tree_constant objects to allocate, +// so make the grow_size large. +octave_allocator +tree_constant::allocator (sizeof (tree_constant), 1024); Octave_map tree_constant::map_value (void) const