コード例 #1
0
ファイル: chunk_alloc.hpp プロジェクト: HerraHuu/stan
 /**
  * Free all memory used by the stack allocator other than the
  * initial block allocation back to the system.  Note:  the
  * destructor will free all memory.
  */
 inline void free_all() {
   // frees all BUT the first (index 0) block
   for (size_t i = 1; i < blocks_.size(); ++i)
     if (blocks_[i])
       free(blocks_[i]);
   blocks_.resize(1); 
   recover_all();
 }
コード例 #2
0
ファイル: renderer.cpp プロジェクト: dtbinh/loci-extended
 bool renderer::reset_device(const d3d9::display_settings & config)
 {
     release_all();
     if (resetter.try_reset(config))
     {
         recover_all();
         this->config = config;
         return true;
     }
     return false;
 }
コード例 #3
0
ファイル: agent.cpp プロジェクト: aijunbai/reversi
int Agent::best_choice()
{	
	static int base = 0;
	result[0] = -MAX_INT;
	move_list_len[0] = history->move_list_len(role, step);
	save_all(0);

	temp_move[0] = best_move[0] = 0;
	if(hash->exist(role)){
		 temp_move[0] = best_move[0] = hash->match_best;
	}
	
	if(best_move[0]){
		board->put(best_move[0], role);
		result[0] = estimation(opp_role, 1, -MAX_INT, MAX_INT);
		recover_all(0);
#ifdef VERBOSE
		printf("%d @ (%d, %d) <- %d (best)\n", result[0], xx[best_move[0]], yy[best_move[0]],
		       					history->get_init_index(best_move[0]));
#endif		
	}

	for(register int i = 1; i <= move_list_len[0]; ++i){
		cur_move[0] = history->move(role, step, i);
		if( !board->can_put(cur_move[0], role) || cur_move[0] == temp_move[0])
			continue;
		board->put(cur_move[0], role);
		value[0] = estimation(opp_role, 1, result[0], MAX_INT);
		recover_all(0);
#ifdef VERBOSE
		printf("%d @ (%d, %d) <- %d\n", value[0], xx[cur_move[0]], yy[cur_move[0]],\
 							history->get_init_index(cur_move[0]));
#endif		
		if(value[0] > result[0]){
			result[0] = value[0];
			best_move[0] = cur_move[0];
		}
	}
	hash->insert(result[0], role, H_EXACT, best_move[0], base, step);	// this is for hash history saved file
	return best_move[0];
}
コード例 #4
0
ファイル: stack_alloc.hpp プロジェクト: mcobzarenco/unet
      /**
       * recover memory back to the last start_nested call.
       */
      inline void recover_nested() {
        if (unlikely(nested_cur_blocks_.empty()))
          recover_all();

        cur_block_ = nested_cur_blocks_.back();
        nested_cur_blocks_.pop_back();

        next_loc_ = nested_next_locs_.back();
        nested_next_locs_.pop_back();
        
        cur_block_end_ = nested_cur_block_ends_.back();
        nested_cur_block_ends_.pop_back();
      }
コード例 #5
0
ファイル: bdb_recover.c プロジェクト: UIKit0/OpenSIPS
/**
 * main -- 
 */
int main(int argc, char* argv[])
{
	int ret, ch, i;
	
	ret = 0;
	progname = argv[0];
	
	while ((ch = getopt(argc, argv, "s:h:c:C:r:R:")) != EOF)
	switch (ch) 
	{
		case 's':
		schema_dir = optarg;
		load_schema(optarg);
		break;
		
		case 'c': /*create <tablename> */
		ret = create(optarg);
		break;
		
		case 'C': /*Create all*/
		ret = create_all();
		break;
		
		case 'r': /*recover <filename> */
		ret = recover(optarg);
		break;
		
		case 'R': /*recover_all <MAXFILES> */
		ret = sscanf(optarg,"%i", &i);
		if(ret != 1) return -1;
		ret = recover_all(i);
		break;
		
		case 'h':
		db_home = optarg;
		break;
		
		case '?':
		default:
		return(usage());
		
	}
	
	argc -= optind;
	argv += optind;
	
	/*free mem; close open files.*/
	cleanup();
	
	return ret;
}
コード例 #6
0
ファイル: agent.cpp プロジェクト: aijunbai/reversi
int Agent::estimation(char color, int depth, int alpha, int beta)
{	
	if( !board->able_to_put(color)){
		color = opposite(color);
		if( !board->able_to_put(color)){
			if(!end_game)
				cost->update();
			return eval->value();
		}
	}
	
	temp_move[depth] = best_move[depth] = 0;
	switch(hash->exist(color, alpha, beta, depth)){
		case H_NONE_EXIST: break;
		case H_MATCH_EXIST: temp_move[depth] = best_move[depth] = hash->match_best; break;
		case H_EXACT_EXIST: return hash->match_eval;
	}

	if(depth == max_depth){		//the last search ply, no pv used
		return terminal_eval(color, depth, alpha, beta);
	}

	//pv_found[depth] = false;
	save_all(depth);
	
	if(best_move[depth]){
		board->put(best_move[depth], color);
		value[depth] = estimation(opposite(color), depth+1, alpha, beta);
		recover_all(depth);
		
		if( color == role){
			if( value[depth] > alpha){
				if( (alpha = value[depth]) >= beta){
					return alpha;
				}
				//pv_found[depth] = true;
			}
			result[depth] = value[depth];
		}
		else{
			if(value[depth] < beta){
				if( (beta = value[depth]) <= alpha){
					return beta;
				}
				//pv_found[depth] = true;
			}
			result[depth] = value[depth];
		}		
	}
	else{
		result[depth] = (color == role)? -MAX_INT: MAX_INT;
	}

	move_list_len[depth] = history->move_list_len(color, step+depth);
	for(register int i = 1; i <= move_list_len[depth]; ++i){
		cur_move[depth] = history->move(color, step+depth, i);
		if( !board->can_put(cur_move[depth], color) || cur_move[depth] == temp_move[depth])
			continue;			
		board->put(cur_move[depth], color);
		//if(pv_found[depth] == true){
		//	if(color == role){
		//		value[depth] = estimation(opposite(color), depth+1, beta-1, beta);
		//		if(value[depth] > alpha && value[depth] < beta){
		//			value[depth] = 
		//					estimation(opposite(color), depth+1, alpha, value[depth]);
		//		}
		//	}
		//	else{
		//		value[depth] = estimation(opposite(color), depth+1, alpha, alpha+1);
		//		if(value[depth] > alpha && value[depth] < beta){
		//			value[depth] = 
		//					estimation(opposite(color), depth+1, value[depth], beta);
		//		}
		//	}
		//}
		//else
			value[depth] = estimation(opposite(color), depth+1, alpha, beta);
		
		recover_all(depth);

		if( color == role){
			if( value[depth] > alpha){
				if( (alpha = value[depth]) >= beta){
					history->advance_move(color, step+depth, i);
					hash->insert(alpha, color, H_LOW_BOUND,
							cur_move[depth], depth, step+depth);
					return alpha;
				}
				//(void)((pv_found[depth])? : pv_found[depth] = true);
			}
			if(value[depth] > result[depth]){
				result[depth] = value[depth];
				best_move[depth] = cur_move[depth];
			}
		}
		else{
			if(value[depth] < beta){
				if( (beta = value[depth]) <= alpha){
					history->advance_move(color, step+depth, i);
					hash->insert(beta, color, H_UP_BOUND,
							cur_move[depth], depth, step+depth);
					return beta;
				}
				//(void)((pv_found[depth])? : pv_found[depth] = true);
			}
			if(value[depth] < result[depth]){
				result[depth] = value[depth];
				best_move[depth] = cur_move[depth];
			}
		}		
	}
	hash->insert(result[depth], color, H_EXACT, best_move[depth], depth, step+depth);
	return result[depth];
}
コード例 #7
0
ファイル: agent.cpp プロジェクト: aijunbai/reversi
inline int  Agent::terminal_eval(char color, int depth, int alpha, int beta)
{
	save_all(depth);
	
	if(best_move[depth]){
		board->put(best_move[depth], color);
		if(!end_game)
			cost->update();
		value[depth] = eval->value();
		recover_all(depth);
		if( color == role){
			if( value[depth] > alpha){
				if( (alpha = value[depth]) >= beta){
					return alpha;
				}
			}
			result[depth] = value[depth];
		}
		else{
			if( value[depth] < beta){
				if( (beta = value[depth]) <= alpha){
					return beta;
				}
			}
			result[depth] = value[depth];
		}
	}
	else{
		result[depth] = (color == role)? -MAX_INT: MAX_INT;
	}
	
	move_list_len[depth] = history->move_list_len(color, step+depth);
	for(register int i = 1; i <= move_list_len[depth]; ++i){
		cur_move[depth] = history->move(color, step+depth, i);
		if( !board->can_put(cur_move[depth], color) || cur_move[depth] == temp_move[depth])
			continue;	
		board->put(cur_move[depth], color);
		if(!end_game)
			cost->update();
		value[depth] = eval->value();
		recover_all(depth);

		if( color == role){
			if( value[depth] > alpha){
				if( (alpha = value[depth]) >= beta){
					history->advance_move(color, step+depth, i);
					hash->insert(alpha, color, H_LOW_BOUND,
							cur_move[depth], depth, step+depth);
					return alpha;
				}
			}
			if( value[depth] > result[depth]){
				result[depth] = value[depth];
				best_move[depth] = cur_move[depth];
			}
		}
		else{
			if( value[depth] < beta){
				if( (beta = value[depth]) <= alpha){
					history->advance_move(color, step+depth, i);
					hash->insert(beta, color, H_UP_BOUND,
							cur_move[depth], depth, step+depth);
					return beta;
				}
			}
			if( value[depth] < result[depth]){
				result[depth] = value[depth];
				best_move[depth] = cur_move[depth];
			}
		}
	}
	
	hash->insert(result[depth], color, H_EXACT, best_move[depth], depth, step+depth);
	return result[depth];
}