Ejemplo n.º 1
0
int main(void) {
    int total_size, choice, request_size;

    frame_echo("\tB U D D Y   S Y S T E M  R E Q U I R E M E N T S");

    printf("*  Enter the Size of the memory  :  ");

    scanf("%d", &total_size);

    while (1) {
        frame_echo("\tB U D D Y   S Y S T E M ");
        puts(" *  1)\tLocate the process into the Memory");
        puts(" *  2)\tRemove the process from Memory");
        puts(" *  3)\tTree structure for Memory allocation Map");
        puts(" *  4)\tExit");
        printf(" *  Enter your choice : ");

        scanf(" %d", &choice);

        switch (choice) {
            case 1:
                frame_echo("\tM E M O R Y   A L L O C A T I O N ");
                printf(" *  Enter the Process size  : ");

                scanf("%d", &request_size);

                segmentalloc(total_size, request_size);

                break;
            case 2:
                frame_echo("\tM E M O R Y   D E A L L O C A T I O N ");
                printf(" *  Enter the process size  :  ");

                scanf("%d", &request_size);

                makefree(request_size);

                break;
            case 3:
                frame_echo("\tM E M O R Y   A L L O C A T I O N   M A P ");

                printing(total_size, 0);

                putchar('\n');

                break;
            default:
                return 0;
        }
    }
}
Ejemplo n.º 2
0
int main()
{
	int totsize,totalalloc,ch,n,req=0;

	for(i=0;i<80;i++) printf("%c",5);
	printf("\n	************************************************************");
	printf("\n 	WELCOME TO (LAZY) BUDDY KERNEL MEMORY ALLOCATOR SIMULATION  ");
	printf("\n	************************************************************\n");
	for(i=0;i<80;i++) printf("%c",5);
	printf("\n We will run the simulation with a memory size = 1024 x (2's power) Bytes");
	printf("\n For power=1, it is 2 power 1 , 3 is 2 power 3 etc. ");
	printf("\n Our default is 1024 and if you enter power 0, it will stay 1024\n");
	printf("\n Enter the POWER OF 2 with which we will multiply default memory size: ");
	scanf("%d",&n);
	
	if (n>5)
		{
			printf("\n Sorry ..we do not support that much of memory in this simulation ...");
			exit(0);
		}
	
	totsize=1024*power(2,n);
	printf("\n TOTAL SYSTEM MEMORY IN BYTES FOR SIMULATION=%d \n", totsize);
	maxlevel=getLevel(totsize);
	maxnodes=power(2,maxlevel+1)-1;
	
	printf("\n ****************************************************************");
	printf("\n NOTE : MAXIMUM HEIGHT OF FULLY SPLIT BUDDY TREE =%d \n", maxlevel);
	printf("\n Starting from node size of 2 bytes, we can have maximum nodes =%d \n", maxnodes);
	printf("\n Our Array implementation of binary tree has ONLY size = %d ",MAXNODES);
	printf("\n So,accordingly select your memory request size..................");
	printf("\n We will allow a minimum size of 16 bytes");	
	printf("\n ****************************************************************");
	
    printf("\n\n Press a key to continue...");
	getchar();

	while(1)
	{
		for(i=0;i<80;i++) printf("%c",5);
		printf("\n ............................................\n");
		printf("\n LAZY BUDDY  SYSTEM  ALGORITHM SIMULATION....\n");
	
		for(i=0;i<80;i++) printf("%c",5);
		printf("	*  1)   Allocation request \n");
		printf("	*  2)   Free request \n");
		printf("	*  3)   Show Memory allocation \n");
		printf("	*  4)   Enable LAZY mode \n");
		printf("	*  5)   Disable LAZY mode \n");
		printf("	*  6)   End simulation\n");
		for(i=0;i<80;i++) printf("%c",5);
		printf("\n.........  Enter your choice  :  \n");
		scanf("%d",&ch);
		switch(ch)
		{
			case 1:
				//clear_screen();
				printf(" ");
				for(i=0;i<80;i++) printf("%c",5);
				printf(" ");
				printf("A L L O C A T I O N\n");
				for(i=0;i<80;i++) printf("%c",5);
				printf("\n  Enter the request size  : ");
				scanf("%d",&req);
				printf("\n total memmory in system : %d \n",totsize);
				printf("\n memory block allocated so far is : %d \n",totalalloc);
				if (req<16)
					{
						printf("\n Sorry ..minimum size of 16 bytes allowed");
						continue;
					}
				
				if (req <=(totsize-totalalloc))
				{
					totalalloc=totalalloc+segmentalloc(totsize,req);
					printf("\n total memory available is : %d \n",(totsize-totalalloc));
				}
				else
					printf("\n Not enough memory left in system\n");
				break;
			case 2:
				printf(" ");
				for(i=0;i<80;i++) printf("%c",5);
				printf(" ");
				printf("D E A L L O C A T I O N \n");
				for(i=0;i<80;i++) printf("%c",5);
				printf("	* requested  size  :  \n");
				scanf("%d",&req);
				makefree(req);
				break;
			case 3:
				
				printf(" ");
				for(i=0;i<80;i++) printf("%c",5);
				printf("CURRENT  M E M O R Y   A L L O C A T I O N   \n");
				for(i=0;i<80;i++) printf("%c",5);
				printf(" ");
				printing(totsize,0);
				printf(" ");
				for(i=0;i<80;i++) printf("%c",5);
				getchar();
				break;
			case 4:
				printf("LAZY MODE is now enabled..Memory COALESCING WILL BE DELAYED.\n");
				lazy=1;
				continue;
			case 5:
				printf(" Lazy mode is NOW DISABLED..Now free any block to reclaim all possible cases...\n");
				lazy=0;
				continue;  
			case 6: 
				printf("\n Thank you for using memory allocator simulation ..GoodBye ");
				exit(0);	
			default:
				printf("\n We expect input 1 to 6 only... ");
			 	continue;
		}
	}
	
}