コード例 #1
0
/*
Vérification du mode:
	-n : next_fit
	-f : first_fit
	-b : best_fit
*/
void verification_mode(char* mode) {

	int* tab_objets = (int*) malloc(sizeof(int) * n_objets);

	if (strcmp(mode, "-n") == 0) {
		printf("Mode NextFit : OK\n");
		next_fit(tab_objets);
		return;
	}
	if (strcmp(mode, "-f") == 0) {
		printf("Mode FirstFit : OK\n");
		first_fit(tab_objets);
		return;
	}
	if (strcmp(mode, "-b") == 0) {
		printf("Mode BestFit : OK\n");
		best_fit(tab_objets);
		return;
	}

	free(tab_objets);

	perror("Le mode n'existe pas...");
	exit(EXIT_FAILURE);
}
コード例 #2
0
 explicit const_partimator_generic(
     const Decision &decis = Decision(),
     const vertex &vtx = vertex())
     : decis_(decis)
     , pit_(vtx)
 {
     decis_.init();
     if (!pit_->the_end())
         next_fit();
 }
コード例 #3
0
void *free_allocation(info_p handler, long n_bytes){
	int full_mem=0;
	
	if(n_bytes < 0){
		printf("Free Allocation Error: requested negative space\n");
		return NULL;
	}
	
	if(handler->n_bytes < n_bytes){
		printf("Free Allocation Error: requested too much space\n");
		return NULL; //User requested more space than permitted
	}
	
	if(n_bytes == handler->n_bytes){
		//printf("request:%lu; bytes: %lu; declaring full memory\n", n_bytes, handler->n_bytes);
		full_mem=1;
	}
	
	if(handler->free_list == NULL){
		return NULL;
	}
	
	void *mem = handler->memptr-4;
	//printf("free list head: %p; size of mem is: %lu\n",handler->free_list, *(long *)mem);
	
	switch(handler->flags){
		case (FREE1_ALLOC): //first fit
			return first_fit(handler, handler->free_list, n_bytes,full_mem);
			break;
		case (FREE2_ALLOC): //next fit
			return next_fit(handler, n_bytes);
			break;
		case (FREE3_ALLOC): //best fit
			return best_fit(handler, n_bytes);
			break;
		case (FREE4_ALLOC): //worst fit
			return worst_fit(handler, n_bytes);
			break;
		default: //should never happen
			return NULL;
	}
	
	printf("Not enough memory to allocate\n");
	return NULL;
}
コード例 #4
0
ファイル: mymalloc.c プロジェクト: valleyjo/cs449
/*
 * ----------------------------------------------------------------------------
 * Allocate space for a given dynamic memory request. The spaces are kept track
 * of by a linked list with nodes that store pertinant data RE: the allocation
 * ----------------------------------------------------------------------------
 */
void *my_next_fit_malloc(int size){

  // if this is the first call
  if (first == 0)
    return (void*)(init_list(size) + 1);

  else{
    Node n = next_fit(size);

    if (n == NULL)
      return (extend_heap(size) + 1);

    else{
      cur = n;
      return n;
    }
  }
}
コード例 #5
0
ファイル: main.cpp プロジェクト: wengduo/item
int main()
{
	printf("请输入内存大小\n");
	int n;
	scanf("%d", &n);
	NODE *phead;  //空闲链
	init_list(&phead, 0);
	init_list_a(phead, n);
	//init_list_b(phead, n);
	NODE *head;
	init_list(&head, 0);
	NODE *hd;
	init_list(&hd, 0);
	printf("首次适应算法-1 循环首次适应算法-2 最佳适应算法-3 最坏适应算法-4\n");
	int ch;
	scanf("%d", &ch);
	while (1)
	{
		if (ch == 1)
		{
			first_fit(phead, head, hd);
			break;
		}
		else if (ch == 2)
		{
			next_fit(phead, head);
			break;
		}
		else if (ch == 3)
		{
			best_fit(phead, head);
			break;
		}
		else if (ch == 4)
		{
			best_fit1(phead, head);
			break;
		}
	}
	return 0;
}
コード例 #6
0
ファイル: memory.cpp プロジェクト: thornb/pj3
//only add function called from SRT or RR.  Determines which memory algorithm to use
bool Memory::add_memory(char proc, int proc_size, int time){

    if(algo == "First-Fit"){
        first_fit(proc, proc_size, time);   
    }

    else if(algo == "Next-Fit"){
        next_fit(proc, proc_size, time);   
    }

    else if(algo == "Best-Fit"){
        best_fit(proc, proc_size, time);   
    }
    else{
        return false;
    }

    printMem(time);

    return true;
}
コード例 #7
0
 this_t &operator++()
 {
     ++pit_;
     next_fit();
     return *this;
 }