瀏覽代碼

Added global count enabler.

woollybah 5 年之前
父節點
當前提交
e5fcf36846
共有 4 個文件被更改,包括 17 次插入7 次删除
  1. 1 0
      blitz.mod/blitz.bmx
  2. 9 6
      blitz.mod/blitz_gc.c
  3. 5 1
      blitz.mod/blitz_object.c
  4. 2 0
      blitz.mod/blitz_object.h

+ 1 - 0
blitz.mod/blitz.bmx

@@ -556,6 +556,7 @@ End Rem
 Function IsEmptyArray:Int(obj:Object)="int bbObjectIsEmptyArray(BBOBJECT)!"
 Function IsEmptyArray:Int(obj:Object)="int bbObjectIsEmptyArray(BBOBJECT)!"
 
 
 Function DumpObjectCounts(buffer:Byte Ptr, size:Int, includeZeros:Int)="bbObjectDumpInstanceCounts"
 Function DumpObjectCounts(buffer:Byte Ptr, size:Int, includeZeros:Int)="bbObjectDumpInstanceCounts"
+Global CountObjectInstances:Int="bbCountInstances"
 
 
 End Extern
 End Extern
 
 

+ 9 - 6
blitz.mod/blitz_gc.c

@@ -107,12 +107,15 @@ BBObject * bbGCAllocObject( int sz,BBClass *clas,int flags ){
 	++bbGCAllocCount;
 	++bbGCAllocCount;
 	#endif
 	#endif
 	q->clas=clas;
 	q->clas=clas;
-	bbAtomicAdd(&clas->instance_count, 1);
-	//if( flags & BBGC_FINALIZE ){
-		GC_finalization_proc ofn;
-		void *ocd;
-		GC_REGISTER_FINALIZER_NO_ORDER( q,gc_finalizer,clas,&ofn,&ocd );
-	//}
+	if (bbCountInstances) {
+		bbAtomicAdd(&clas->instance_count, 1);
+	} else {
+		if( flags & BBGC_FINALIZE ){
+			GC_finalization_proc ofn;
+			void *ocd;
+			GC_REGISTER_FINALIZER_NO_ORDER( q,gc_finalizer,clas,&ofn,&ocd );
+		}
+	}
 	return q;	
 	return q;	
 }
 }
 
 

+ 5 - 1
blitz.mod/blitz_object.c

@@ -3,6 +3,8 @@
 
 
 #define REG_GROW 256
 #define REG_GROW 256
 
 
+int bbCountInstances = 0;
+
 static BBClass **reg_base,**reg_put,**reg_end;
 static BBClass **reg_base,**reg_put,**reg_end;
 static BBInterface **ireg_base,**ireg_put,**ireg_end;
 static BBInterface **ireg_base,**ireg_put,**ireg_end;
 
 
@@ -62,7 +64,9 @@ BBObject *bbObjectAtomicNewNC( BBClass *clas ){
 void bbObjectFree( BBObject *o ){
 void bbObjectFree( BBObject *o ){
 	BBClass *clas=o->clas;
 	BBClass *clas=o->clas;
 
 
-	bbAtomicAdd(&clas->instance_count, -1);
+	if (bbCountInstances) {
+		bbAtomicAdd(&clas->instance_count, -1);
+	}
 
 
 	if (clas->dtor != bbObjectDtor) {
 	if (clas->dtor != bbObjectDtor) {
 		clas->dtor( o );
 		clas->dtor( o );

+ 2 - 0
blitz.mod/blitz_object.h

@@ -82,6 +82,8 @@ BBObject*	bbObjectArraycast( BBObject *o );
 void		bbObjectRegisterType( BBClass *clas );
 void		bbObjectRegisterType( BBClass *clas );
 BBClass**	bbObjectRegisteredTypes( int *count );
 BBClass**	bbObjectRegisteredTypes( int *count );
 void bbObjectDumpInstanceCounts();
 void bbObjectDumpInstanceCounts();
+extern int bbCountInstances;
+
 
 
 void bbObjectRegisterInterface( BBInterface * ifc );
 void bbObjectRegisterInterface( BBInterface * ifc );
 BBInterface **bbObjectRegisteredInterfaces( int *count );
 BBInterface **bbObjectRegisteredInterfaces( int *count );