Esempio n. 1
0
int main(int argc, char ** argv) {
	int opterr = 0;
    unsigned int _basic_block_size =  128;
    unsigned int _length  = 524288; 
    
    int c;
   
   	while( (c = getopt(argc, argv, "b:s:") ) != -1) {
    	switch(c) {
			case 'b':
				_basic_block_size = atoi(optarg);
				break;
			case 's':
				_length = atoi(optarg)*1024;
				break;
			case '?':
				break;
			default:
				abort();
		}
    }   
  
  	init_allocator(_basic_block_size, _length);
	ackerman_main();
	release_allocator();
}
Esempio n. 2
0
int main(int argc, char ** argv) {

	// Register release_allocator() to run when program exits normally.
	if( atexit(release_allocator) != 0 )
		err_sys("Can't register release_allocator().\n");

	// PARSE INPUT ARGUMENTS
	unsigned int BASIC_BLOCK_SIZE;
	unsigned int MEMORY_LENGTH;
	int b_flag = 0,		// Used to provide default argument values if
		s_flag = 0;	// none are given.
	_Bool o_flag = 0;
	opterr = 0;			// Disable getopt() error message.

	// gets the arguments from the command line and rounds them up to the nearest
	// power of two
	int c;
	set_output_flag(0);
	while( (c = getopt(argc, argv, OPTSTR)) != -1 ){
		switch(c){
			case 'b':
					 b_flag = 1;
					 BASIC_BLOCK_SIZE = convert(atoi(optarg));
					 break;
			case 's':
					 s_flag = 1;
					 MEMORY_LENGTH = convert(atoi(optarg));
					 break;
			case 'o':
					 set_output_flag(1);
					 break;
		};
	}

	// Provide default arguments if needed.
	if ( !(b_flag) ){
		BASIC_BLOCK_SIZE = 128; // Set default to 128 B
		printf("No argument provided; using default BASIC_BLOCK_SIZE: 128 B\n");
	}
	if ( !(s_flag) ){
		MEMORY_LENGTH = 524288; // Set default to 512 KiB
		printf("No argument provided; using default MEMORY_LENGTH: 512 KiB\n\n");
	}
	
	printf("Basic Block Size: %d B\nMemory Size: %d B\n",
			BASIC_BLOCK_SIZE,MEMORY_LENGTH);
	//==============================================================================

	// initialize the allocator
	unsigned int allocate_flag = init_allocator(BASIC_BLOCK_SIZE, MEMORY_LENGTH);

	if(allocate_flag == 0){
		printf("\nAllocator initialization error.");
		return 0;
	}
	// Otherwise, run ackerman_main()
	ackerman_main();

	return 0;
}
Esempio n. 3
0
int main(int argc, char ** argv) {
	int a = init_allocator(50, 1000000);
	/*printf("%s %d\n", "Total memory allocated" ,a );
	printf("%s %d\n", "Total blocks" ,a/4 );
	//print_freeList();
	//check_list();
	//print_freeList();
	void * b = my_malloc(16000);
	void * d = my_malloc(16000);
	void * e = my_malloc(16000);
	void * f = my_malloc(16000);
	void * c = my_malloc(81000);
	int x = my_free(b);
	int y = my_free(d);
	int r = my_free(e);
	int t = my_free(f);
	int p = my_free(c);*/

  ackerman_main();
}
Esempio n. 4
0
int main(int argc, char ** argv) {

	unsigned long long b, M = 0;
	int opt;
	//char input[256];
	while((opt = getopt(argc, argv, "b::s::")) != -1){
		
		switch (opt){
			case 'b':{
				if(argv[2]) b = atoi(argv[2]);
				else b=32;
				//printf("b: %s \n",argv[2]);
				break;
			}
			case 's':{
				if(argv[4]) M = atoi(argv[4]);
				else M = 128*1024*1024;
				//printf("M: %s \n",argv[4]);
				break;
			}
			default:{
				fprintf(stderr, "Usage: %s [-b blocksize] [-s] memsize\n",argv[0]);
				exit(EXIT_FAILURE);
			}
		}
		
	}
	if (b == 0 || M == 0 ){
		b = 32;
		M = 128*1024*1024;
	}
	printf("using values:\nb: %d \nM: %d \n",b,M);
	
	// init_allocator(basic block size, memory length)
	init_allocator(b,M);
	
	//init_allocator(32,128*1024*1024);
	
  
	
	ackerman_main();
	
	//	my_allocator DEMO
  /* 
	init_allocator(32,256*32);
	PrintList();
	cout<<endl;
	PrintList2();
	cout<<endl;
	int* block1 = (int*) my_malloc(64);//allocates 128 block
	int* block2 = (int*) my_malloc(12);//allocates 32 block
	int* block3 = (int*) my_malloc(12);//allocates 32 block
	int* block4 = (int*) my_malloc(32);//allocates 64 block
	cout<<"PRINTING AFTER ALLOCATING BLOCKS"<<endl;
	PrintList();
	cout<<endl;
	PrintList2();
	
	my_free(block1);
	my_free(block2);
	my_free(block3);
	my_free(block4);
	cout<<endl<<"PRINTING AFTER FREEING BLOCKS"<<endl;
	PrintList();
	cout<<endl;
	PrintList2();
	 */
	//atexit(release_allocator());
  release_allocator();
}