Esempio n. 1
0
	//** space ctrl **//
	void Hash::_try_rehash(){
		if(m_slot_count==0 || (1+m_item_count)*2>m_slot_count){
			// save old
			PNODE* pOldeSlotArray =m_pSlotArray;
			const int64_t old_slot_count =m_slot_count;

			// new
			m_slot_count =m_slot_count ? m_slot_count*2 : 32;
			const int64_t s =sizeof(PNODE) * m_slot_count;
			m_pSlotArray =reinterpret_cast< PNODE* >(ALLOCATE(s));
			memset(m_pSlotArray, 0, (size_t)s);

			// copy
			m_item_count =0;
			for(int64_t i=0; i<old_slot_count; ++i){
				PNODE node =pOldeSlotArray[i];
				while(node){
					PNODE tmp =node->next;
					set(node->key, node->value);
					RELEASE_POINTER(node->key);
					RELEASE_POINTER(node->value);
					DEALLOCATE(node);
					node =tmp;
				}
			}
			DEALLOCATE(pOldeSlotArray);
		}
	}
Esempio n. 2
0
	void Hash::optimize(int64_t gap){
		if(gap < 32) gap =32;
		// save old
		PNODE* pOldeSlotArray =m_pSlotArray;
		const int64_t old_slot_count =m_slot_count;

		// new
		const int64_t n =m_item_count * 3;
		m_slot_count =n%gap ? (n/gap + 1)*gap : n;
		if(m_slot_count < gap){
			m_slot_count =gap;
		}
		if(m_slot_count == old_slot_count){
			return;
		}

		const int64_t s =sizeof(PNODE) * m_slot_count;
		m_pSlotArray =reinterpret_cast< PNODE* >(ALLOCATE(s));
		memset(m_pSlotArray, 0, (size_t)s);
		m_item_count =0;

		// copy
		for(int64_t i=0; i<old_slot_count; ++i){
			PNODE node =pOldeSlotArray[i];
			while(node){
				PNODE tmp =node->next;
				set(node->key, node->value);
				RELEASE_POINTER(node->key);
				RELEASE_POINTER(node->value);
				DEALLOCATE(node);
				node =tmp;
			}
		}
		DEALLOCATE(pOldeSlotArray);
	}
Esempio n. 3
0
	void Hash::_release_node(const int64_t slot, PNODE node){
		RELEASE_POINTER(node->key);
		RELEASE_POINTER(node->value);
		if(node->prev){
			node->prev->next =node->next;
		}
		else{
			m_pSlotArray[slot] =node->next;
		}
		if(node->next){
			node->next->prev =node->prev;
		}
		DEALLOCATE(node);
		m_item_count -=1;
	}
Esempio n. 4
0
	void Hash::clear(){
		for(int64_t i=0; i<m_slot_count; ++i){
			PNODE node =m_pSlotArray[i];
			while(node){
				PNODE tmp =node->next;
				RELEASE_POINTER(node->key);
				RELEASE_POINTER(node->value);
				DEALLOCATE(node);
				node =tmp;
			}
		}
		DEALLOCATE(m_pSlotArray);
		m_pSlotArray =0;
		m_slot_count =0;
		m_item_count =0;
	}
Esempio n. 5
0
/* 释放所有资源,断开链接 */
void CVMR_Capture::CloseInterfaces(void)
{
    HRESULT hr;
   	// 停止媒体回放
    if(m_pMC) hr = m_pMC->Stop();	    
    m_psCurrent = STOPPED;

    // 释放并清零接口指针
	if(m_pCamOutPin)
		m_pCamOutPin->Disconnect();

	RELEASE_POINTER(m_pCamOutPin);        
    RELEASE_POINTER(m_pMC);    
    RELEASE_POINTER(m_pGB);    
    RELEASE_POINTER(m_pWC);	
	RELEASE_POINTER(m_pDF);

	// 释放分配的内存
	if(m_pFrame!=NULL)
		delete []m_pFrame;
}
//------------------------------------------
EXPORT_C void skTreeNodeObject::getInstanceVariables(skRValueTable& table)
//------------------------------------------
{
  if (m_Node){
    for (unsigned int i=0;i<m_Node->numChildren();i++){
      skTreeNode * var=m_Node->nthChild(i);
      skRValue * value=skNEW(skRValue());
      SAVE_POINTER(value);
      value->assignObject(new skTreeNodeObject(var->label(),var,false),true);
      table.insertKeyAndValue(var->label(),value);
      RELEASE_POINTER(value);
    }
  }
}
//---------------------------------------------------
skInterpreter::StatementReturnCode skInterpreter::executeForEachStat(skStackFrame& frame,skForEachNode * n,skRValue& r)
//---------------------------------------------------
{
    StatementReturnCode bRet=SRC_CONTINUE;
    skString checked_id;
    SAVE_VARIABLE(checked_id);
    checked_id=checkIndirectId(frame,n->getId());
    skRValue expr;
    SAVE_VARIABLE(expr);
    expr=evaluate(frame,n->getExpr());
    if (expr.type()==skRValue::T_Object) {
        skExecutableIterator * iterator=0;
        if (n->getQualifier().length())
            iterator=expr.obj()->createIterator(n->getQualifier());
        else
            iterator=expr.obj()->createIterator();
        if (iterator) {
            SAVE_POINTER(iterator);
            skRValue value;
            SAVE_VARIABLE(value);
            while ((iterator->next(value) && bRet==SRC_CONTINUE)) {
#ifndef EXCEPTIONS_DEFINED
                if (frame.getContext().getError().getErrorCode()!=skScriptError::NONE)
                    break;
#endif
                addLocalVariable(frame.getVars(),checked_id,value);
                if (n->getStats()) {
                    bRet=executeStats(frame,n->getStats(),r);
                }
            }
            RELEASE_VARIABLE(value);
            RELEASE_POINTER(iterator);
            delete iterator;
        } else
            runtimeError(frame,skSTR("Object could not create an iterator, in a foreach statement\n"));
    } else
        runtimeError(frame,skSTR("Cannot apply foreach to a non-executable object\n"));
    RELEASE_VARIABLE(expr);
    RELEASE_VARIABLE(checked_id);
    // once broken out, can continue executing
    if (bRet==SRC_BREAK)
        bRet=SRC_CONTINUE;
    return bRet;
}