Exemplo n.º 1
0
std::vector<pBlock> GarbageCollector::
        runUntilComplete(unsigned frame_counter)
{
    BlockCache::cache_t cacheCopy = cache_->clone();
    size_t free_memory = availableMemoryForSingleAllocation();
    size_t allocatedMemory = BlockCacheInfo::cacheByteSize (cacheCopy);

    auto sorted = getSorted(frame_counter);

    std::vector<pBlock> R;
    R.reserve (sorted.size ());

    // Go from oldest to newest
    for (pBlock b : sorted)
    {
        if (allocatedMemory < free_memory*MAX_FRACTION_FOR_CACHES)
            break;

        Heightmap::Block::pGlBlock glblock = b->glblock;
        size_t blockMemory = glblock
                ? glblock->allocated_bytes_per_element() * b->block_layout().texels_per_block ()
                : 0;

        allocatedMemory = clamped_sub(allocatedMemory, blockMemory);
        R.push_back (b);
    }

    return R;
}
Exemplo n.º 2
0
std::vector<pBlock> GarbageCollector::
        releaseNOldest(unsigned frame_counter, unsigned N)
{
    auto sorted = getSorted(frame_counter);

    std::vector<pBlock> R;
    R.reserve (N);

    // Go from oldest to newest
    for (pBlock b : sorted)
        if (R.size () < N)
            R.push_back (b);

    return R;
}
Exemplo n.º 3
0
/**
	get sorted nodes accroding to degree/strength/.....
*/
int 
getSortedNodes_degree(struct network * target,
                                int                   order, /* 0 : descending   1: ascending*/
                                int *                rids)   /*returnted nodes*/
{
	int i;
	double *vals;
	int nodeNum;
	nodeNum=target->nodeNum;
	vals=(double*)mem_alloc((nodeNum+1)*sizeof(double));
	for(i=1;i<=nodeNum;i++)
	{
		rids[i]=i;
		vals[i]=(double)target->nodes[i].numadj;
	}
	
	getSorted(rids,vals,nodeNum,order);	
	mem_free(vals);
	
	return 0;
}
Exemplo n.º 4
0
/**
	get sorted nodes accroding to degree/strength/.....
*/
int 
getSortedNodes(struct netInfo * netinfo,
					int                   type,    /* degree/strength/.....  */
                                int                   order, /* 0 : descending   1: ascending*/
                                int *                rids)   /*returnted nodes*/
{
	int i;
	double *vals;
	int *shell;
	int nodeNum;
	nodeNum=netinfo->target->nodeNum;
	vals=(double*)mem_alloc((nodeNum+1)*sizeof(double));
	shell=(int*)mem_alloc((nodeNum+1)*sizeof(int));
	for(i=1;i<=nodeNum;i++)
	{
		rids[i]=i;
	}
	
	switch(type)
	{
		case DEGREE:
			for(i=1;i<=nodeNum;i++)
			{
				vals[i]=(double)netinfo->ninfo[i].degree;
			}
			break;

		case STRENGTH:
			for(i=1;i<=nodeNum;i++)
			{
				vals[i]=netinfo->ninfo[i].strength;
			}
			break;
	
		case LOAD:
			for(i=1;i<=nodeNum;i++)
			{
				vals[i]=netinfo->ninfo[i].load;
			}
			break;
		case BETWEENNESS:
			for(i=1;i<=nodeNum;i++)
			{
				vals[i]=netinfo->ninfo[i].betweeness;
			}
		case KSHELL:
			getKshell(netinfo->target, shell);
			for(i=1;i<=nodeNum;i++)
			{
				vals[i]=shell[i];
			}
			break;	
	}
	
	getSorted(rids,vals,nodeNum,order);
	
	
	mem_free(vals);
	mem_free(shell);
	return 0;
}