[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Toon-members] TooN/internal allocator.hh mbase.hh vbase.hh
From: |
Edward Rosten |
Subject: |
[Toon-members] TooN/internal allocator.hh mbase.hh vbase.hh |
Date: |
Tue, 10 Feb 2009 10:35:06 +0000 |
CVSROOT: /cvsroot/toon
Module name: TooN
Changes by: Edward Rosten <edrosten> 09/02/10 10:35:06
Modified files:
internal : allocator.hh mbase.hh vbase.hh
Log message:
Simplify SliceHolder, and make classes derive from sliceholder,
rather than having it as a member. This prevents any space being
allocated when nonw is needed.
The output of the following program is:
80
84
80
#include <iostream>
using namespace std;
struct nothing{};
struct base{
double d[10];
};
struct derived: public base{
nothing n;
};
struct derived2: public base, public nothing{
};
int main()
{
cout << sizeof(base) << endl;
cout << sizeof(derived) << endl;
cout << sizeof(derived2) << endl;
}
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/TooN/internal/allocator.hh?cvsroot=toon&r1=1.8&r2=1.9
http://cvs.savannah.gnu.org/viewcvs/TooN/internal/mbase.hh?cvsroot=toon&r1=1.9&r2=1.10
http://cvs.savannah.gnu.org/viewcvs/TooN/internal/vbase.hh?cvsroot=toon&r1=1.6&r2=1.7
Patches:
Index: allocator.hh
===================================================================
RCS file: /cvsroot/toon/TooN/internal/allocator.hh,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- allocator.hh 9 Feb 2009 14:26:37 -0000 1.8
+++ allocator.hh 10 Feb 2009 10:35:06 -0000 1.9
@@ -181,6 +181,33 @@
};
+////////////////////////////////////////////////////////////////////////////////
+//
+// A class similar to mem, but to hold the stride information. It is only
needed
+// for -1. For +int and -2, the stride is part fo teh type, or implicit.
+
+template<int s> struct StrideHolder
+{
+ //Constructos ignore superfluous arguments
+ StrideHolder(){}
+ StrideHolder(int){}
+
+ int stride() const{
+ return s;
+ }
+};
+
+template<> struct StrideHolder<-1>
+{
+ StrideHolder(int s)
+ :my_stride(s){}
+
+ const int my_stride;
+ int stride() const {
+ return my_stride;
+ }
+};
+
Index: mbase.hh
===================================================================
RCS file: /cvsroot/toon/TooN/internal/mbase.hh,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -b -r1.9 -r1.10
--- mbase.hh 8 Feb 2009 19:18:57 -0000 1.9
+++ mbase.hh 10 Feb 2009 10:35:06 -0000 1.10
@@ -27,39 +27,6 @@
////////////////////////////////////////////////////////////////////////////////
-//
-// A class similar to mem, but to hold the stride information. It is only
needed
-// for -1. For +int and -2, the stride is part fo teh type, or implicit.
-
-template<int s> struct StrideHolder
-{
- //Constructos ignore superfluous arguments
- StrideHolder(){}
- StrideHolder(int){}
-
- int get(const void*) const{
- return s;
- }
-};
-
-template<> struct StrideHolder<-1>
-{
- StrideHolder(int s)
- :stride(s){}
-
- const int stride;
- int get(const void*) const {
- return stride;
- }
-};
-
-template<> struct StrideHolder<-2>{
- template<class C> int get(const C* c) const {
- return c->tied_stride();
- }
-};
-
-////////////////////////////////////////////////////////////////////////////////
//Closure used to acquire strides
//-1 means dynamic stride
//-2 means dynamic stride is tied to size
@@ -166,38 +133,32 @@
// Row major matrix implementation
//
-template<int Rows, int Cols, class Precision, int Stride, class Mem> struct
GenericRowMajor: public Mem
+template<int Rows, int Cols, class Precision, int Stride, class Mem> struct
GenericRowMajor: public Mem, StrideHolder<Stride>
{
//Slices can never have tied strides
static const int SliceStride = Stride == -2?-1: Stride;
- //This little hack returns the stride value if it exists,
- //or one of the implied strides if they exist.
- int tied_stride() const{
- //Only valid if stride is -2
- return num_cols();
- }
- StrideHolder<Stride> my_stride;
int stride() const {
- return my_stride.get(this);
+ if(Stride == -2)
+ return num_cols();
+ else
+ return StrideHolder<Stride>::stride();
}
-
//Optional constructors
-
GenericRowMajor(){}
GenericRowMajor(Precision* p)
:Mem(p) {}
GenericRowMajor(Precision* p, int s)
- :Mem(p),my_stride(s) {}
+ :Mem(p),StrideHolder<Stride>(s) {}
GenericRowMajor(Precision* p, int r, int c)
:Mem(p, r, c) {}
GenericRowMajor(Precision* p, int r, int c, int stride)
- :Mem(p, r, c),my_stride(stride) {}
+ :Mem(p, r, c),StrideHolder<Stride>(stride) {}
GenericRowMajor(int r, int c)
:Mem(r, c) {}
@@ -249,20 +210,16 @@
// Column major matrix implementation
//
-template<int Rows, int Cols, class Precision, int Stride, class Mem> struct
GenericColMajor: public Mem
+template<int Rows, int Cols, class Precision, int Stride, class Mem> struct
GenericColMajor: public Mem, public StrideHolder<Stride>
{
//Slices can never have tied strides
static const int SliceStride = Stride == -2?-1: Stride;
- //This little hack returns the stride value if it exists,
- //or one of the implied strides if they exist.
- int tied_stride() const{
- //Only valid if stride is -2
- return num_rows();
- }
- StrideHolder<Stride> my_stride;
int stride() const {
- return my_stride.get(this);
+ if(Stride == -2)
+ return num_rows();
+ else
+ return StrideHolder<Stride>::stride();
}
@@ -274,13 +231,13 @@
:Mem(p) {}
GenericColMajor(Precision* p, int s)
- :Mem(p),my_stride(s) {}
+ :Mem(p),StrideHolder<Stride>(s) {}
GenericColMajor(Precision* p, int r, int c)
:Mem(p, r, c) {}
GenericColMajor(Precision* p, int r, int c, int stride)
- :Mem(p, r, c),my_stride(stride) {}
+ :Mem(p, r, c),StrideHolder<Stride>(stride) {}
GenericColMajor(int r, int c)
:Mem(r, c) {}
Index: vbase.hh
===================================================================
RCS file: /cvsroot/toon/TooN/internal/vbase.hh,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- vbase.hh 8 Feb 2009 19:18:58 -0000 1.6
+++ vbase.hh 10 Feb 2009 10:35:06 -0000 1.7
@@ -5,33 +5,6 @@
////////////////////////////////////////////////////////////////////////////////
//
-// A class similar to mem, but to hold the stride information. It is only
needed
-// for -1. For +int and -2, the stride is part fo teh type, or implicit.
-
-template<int s> struct VStrideHolder
-{
- //Constructos ignore superfluous arguments
- VStrideHolder(){}
- VStrideHolder(int){}
-
- int stride() const{
- return s;
- }
-};
-
-template<> struct VStrideHolder<-1>
-{
- VStrideHolder(int s)
- :my_stride(s){}
-
- const int my_stride;
- int stride() const {
- return my_stride;
- }
-};
-
-////////////////////////////////////////////////////////////////////////////////
-//
// Slice holding class
//
@@ -69,11 +42,10 @@
// Generic implementation
//
-template<int Size, typename Precision, int Stride, typename Mem> struct
GenericVBase: public Mem
+template<int Size, typename Precision, int Stride, typename Mem> struct
GenericVBase: public Mem, public StrideHolder<Stride>
{
- VStrideHolder<Stride> my_stride;
int stride() const{
- return my_stride.stride();
+ return StrideHolder<Stride>::stride();
}
//Optional constuctors
@@ -84,11 +56,11 @@
{}
GenericVBase(Precision* d, int stride)
- :Mem(d),my_stride(stride){
+ :Mem(d),StrideHolder<Stride>(stride){
}
GenericVBase(Precision* d, int length, int stride)
- :Mem(d, length),my_stride(stride){
+ :Mem(d, length),StrideHolder<Stride>(stride){
}
using Mem::my_data;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Toon-members] TooN/internal allocator.hh mbase.hh vbase.hh,
Edward Rosten <=