[Gridflow-cvs] [svn] commit: r5620 - in /trunk/src: classes1.cxx grid.cxx gridflow.hxx

svn-gridflow at artengine.ca svn-gridflow at artengine.ca
Thu May 6 01:48:18 EDT 2010


Author: matju
Date: Thu May  6 01:48:18 2010
New Revision: 5620

Log:
GridOutlet {Grid buf}

Modified:
    trunk/src/classes1.cxx
    trunk/src/grid.cxx
    trunk/src/gridflow.hxx

Modified: trunk/src/classes1.cxx
==============================================================================
--- trunk/src/classes1.cxx (original)
+++ trunk/src/classes1.cxx Thu May  6 01:48:18 2010
@@ -566,9 +566,9 @@
 			op->name,op->size,in.dim.to_s(),r->dim.to_s());
 	out=new GridOutlet(this,0,in.dim,in.nt);
 	//if (out->inlets.size()==1) post("[#]: 1 receiver with bugger size %s",out->inlets[0]->dim.to_s());
-	if (!out->buf) out->create_buf(); /* force it now (hack) */
-} GRID_FLOW {
-	long moton = out->buf->dim.prod();
+	if (out->fresh) out->create_buf(); /* force it now (hack) */
+} GRID_FLOW {
+	long moton = out->buf.dim.prod();
 	T *rdata = (T *)*r;
 	long loop = r->dim.prod();
 	while (n) {

Modified: trunk/src/grid.cxx
==============================================================================
--- trunk/src/grid.cxx (original)
+++ trunk/src/grid.cxx Thu May  6 01:48:18 2010
@@ -193,7 +193,7 @@
 /* **************** GridOutlet ************************************ */
 
 GridOutlet::GridOutlet(FObject *parent_, int woutlet, const Dim &dim_, NumberTypeE nt_) {
-	parent=parent_; dim=dim_; nt=nt_; dex=0; bufi=0; buf=0; sender=this;
+	parent=parent_; dim=dim_; nt=nt_; dex=0; bufi=0; sender=this; fresh=true;
 	t_atom a[1];
 	SETGRIDOUT(a,this);
 	if (parent) {
@@ -209,13 +209,14 @@
 	// biggest packet size divisible by lcm_factor
 	int32 v = (MAX_PACKET_SIZE/lcm_factor)*lcm_factor;
 	if (v==0) v=MAX_PACKET_SIZE; // factor too big. don't have a choice.
-	buf=new Grid(Dim(v),nt);
+	buf.init(Dim(v),nt);
 #ifdef TRACEBUFS
 	std::ostringstream text;
 	oprintf(text,"GridOutlet: %20s buf for sending to  ",buf->dim->to_s());
 	for (uint i=0; i<inlets.size(); i++) text << " " << (void *)inlets[i]->parent;
 	post("%s",text.str().data());
 #endif
+	fresh=false;
 }
 
 // send modifies dex; send_direct doesn't
@@ -230,10 +231,10 @@
 }
 
 void GridOutlet::flush() {
-	if (!buf) return;
+	if (fresh) return;
 	if (!bufi) return;
-#define FOO(T) send_direct(bufi,(T *)*buf);
-	TYPESWITCH(buf->nt,FOO,)
+#define FOO(T) send_direct(bufi,(T *)buf);
+	TYPESWITCH(buf.nt,FOO,)
 #undef FOO
 	bufi = 0;
 }
@@ -264,10 +265,10 @@
 			send_direct(n,data);
 		} else {
 			//post("send_indirect %d",n);
-			if (!buf) create_buf();
-			int32 v = buf->dim.prod();
+			if (fresh) create_buf();
+			int32 v = buf.dim.prod();
 			if (bufi + n > v) flush();
-			COPY((T *)*buf+bufi,data,n);
+			COPY((T *)buf+bufi,data,n);
 			bufi += n;
 		}
 		if (dex==dim.prod()) finish();

Modified: trunk/src/gridflow.hxx
==============================================================================
--- trunk/src/gridflow.hxx (original)
+++ trunk/src/gridflow.hxx Thu May  6 01:48:18 2010
@@ -347,12 +347,7 @@
 		if(c) COPY(v+a->n+b->n,c->v,c->n);
 	}
 	Card count() {return n;}
-	//Card get     (Card i) const {return v[i];}
 	Card operator[](Card i) const {return v[i];}
-	//const Dim & operator *() const {return *this;}
-	//      Dim & operator *()       {return *this;}
-	//const Dim *operator ->() const {return this;}
-	//      Dim *operator ->()       {return this;}
 /*	Dim *range(Card i, Card j) {return new Dim(...);} */
 	Card prod(Card start=0, Card end=-1) const {
 		if (start<0) start+=n;
@@ -580,7 +575,7 @@
 	NumberTypeE nt;
 	void *data;
 	int state; /* 0:borrowing 1:owning -1:expired(TODO) */
-	Grid(const Dim &dim, NumberTypeE nt, bool clear=false) {
+	Grid(const Dim &dim=Dim(), NumberTypeE nt=int32_e, bool clear=false) {
 		state=1; 
 		init(dim,nt);
 		if (clear) {long size = bytes(); CLEAR((char *)data,size);}
@@ -604,8 +599,7 @@
 		return foo;
 	}
 	~Grid() {if (state==1 && data) free(data);}
-private:
-	void init(const Dim &dim, NumberTypeE nt) {
+	void init(const Dim &dim=Dim(), NumberTypeE nt=int32_e) {
 		this->dim = dim;
 		this->nt = nt;
 		data = 0;
@@ -776,8 +770,9 @@
 	#undef FOO
 	template <class T> void send_2(long n, T *data);
 	void flush(); // goes with send();
-	PtrGrid buf; // temporary buffer
+	Grid buf; // temporary buffer
 	long bufi; // number of bytes used in the buffer
+	bool fresh; /* 0 = buf was inited */
 	template <class T> void send_direct(long n, T *data);
 	void finish();
 	void create_buf();



More information about the Gridflow-cvs mailing list