BBObj *_bbObjNew( BBObjType *type ){ if( type->free.next==&type->free ){ int obj_size=sizeof(BBObj)+type->fieldCnt*4; BBObj *o=(BBObj*)bbMalloc( obj_size*OBJ_NEW_INC ); for( int k=0;k<OBJ_NEW_INC;++k ){ insertObj( o,&type->free ); o=(BBObj*)( (char*)o+obj_size ); } } BBObj *o=type->free.next; unlinkObj( o ); o->type=type; o->ref_cnt=1; o->fields=(BBField*)(o+1); for( int k=0;k<type->fieldCnt;++k ){ switch( type->fieldTypes[k]->type ){ case BBTYPE_VEC: o->fields[k].VEC=_bbVecAlloc( (BBVecType*)type->fieldTypes[k] ); break; default: o->fields[k].INT=0; } } insertObj( o,&type->used ); ++unrelObjCnt; ++objCnt; return o; }
bbGCNode *alloc( size_t size ){ if( allocedBytes>=BBGC_TRIGGER ){ sweep(); #if BBGC_AGGRESSIVE reclaim(); #endif }else{ #if BBGC_INCREMENTAL // size_t tomark=double( allocedBytes ) / double( BBGC_TRIGGER ) * double( unmarkedBytes + allocedBytes ); size_t tomark=double( allocedBytes ) / double( BBGC_TRIGGER ) * double( unmarkedBytes + BBGC_TRIGGER ); markQueued( tomark ); #endif } bbGCNode *p=(bbGCNode*)bbMalloc( size ); *((void**)p)=(void*)0xcafebabe; p->flags=0; size=bbMallocSize( p ); allocedBytes+=size; #if !BBGC_AGGRESSIVE reclaim( size ); #endif return p; }
void *BBStr::operator new( size_t size ){ if( freeStrs.next==&freeStrs ){ BBStr *t=(BBStr*)bbMalloc( sizeof(BBStr)*STR_NEW_INC ); for( int k=0;k<STR_NEW_INC;++k ) insertStr( t++,&freeStrs ); } BBStr *t=freeStrs.next; removeStr( t );insertStr( t,&usedStrs ); return t; }
void _bbDimArray( BBArray *array ){ int k; for( k=0;k<array->dims;++k ) ++array->scales[k]; for( k=1;k<array->dims;++k ){ array->scales[k]*=array->scales[k-1]; } int size=array->scales[array->dims-1]; array->data=bbMalloc( size*4 ); memset( array->data,0,size*4 ); }
void * _bbVecAlloc( BBVecType *type ){ void *vec=bbMalloc( type->size*4 ); memset( vec,0,type->size*4 ); return vec; }