Esempio n. 1
0
conn_t *conn_get_from_mem(int s)
{
    conn_t       *c   = NULL;
    event_t      *rev = NULL;
    event_t      *wev = NULL;

    c   = memory_calloc(sizeof(conn_t));
    rev = memory_calloc(sizeof(event_t));
    wev = memory_calloc(sizeof(event_t));

    if (!c || !rev || !wev) {
        return NULL;
    }
    c->read = rev;
    c->write = wev;
    conn_set_default(c, s);
    return c;
}
Esempio n. 2
0
static pnm
L_init(int width, int height, pnmType type)
{
    pnm self = memory_alloc(sizeof(struct pnm));

    self->width = width;
    self->height = height;
    self->original_type = type;
    self->image = memory_calloc(3*self->width*self->height*sizeof(unsigned short));

    return self;
}
Esempio n. 3
0
/*******************************************************************************
 * Brief - This is the main function in which various functions are tested using 
 * switch cases ,user is given with menu where every function is tested and by 
 * calling memory_information each details are shown to the user. 
 ******************************************************************************/
int main()
{	
    int menuChoice = 0 , subMenuChoice = 0, size = 0 , totalElements = 0;
    char choice ='y';
    int **pointer;
    int	index , number = 0, *arrayPointer[MAX_SIZE], numFree = 0, numRealloc, random, *previousAddress, num;
    pointer = arrayPointer;
    do
    {
    __fpurge(stdin);
    system("clear");
    printf("\n\n\t\tMENU\n\t1. Use memory_alloc or Use memory_calloc\n\t2. Use memory_free\n\t3. Use memory_realloc");
    printf("\n\t4. memory_information\n\t5. free everything");
    printf("\n\nEnter your menuChoice :");
    scanf("%d" , &menuChoice);
    switch(menuChoice)
    {
	case 1:	
	    system("clear");
	    printf("\n\n\t\tSUB-MENU\n\t1. Use memory_alloc \n\t2. Use memory_calloc\n\nEnter your menuChoice :");
	    scanf("%d" , &subMenuChoice);
            switch(subMenuChoice)
            {
                case 1:
            	    system("clear");
	            printf("How many memory_alloc calls u want :");
	    	    scanf("%d",&num);
            	    printf("Size\tAddress\n-----------------\n");
            	    for(index = number ; index < number + num ; index++)
            	    {
 			       size = rand() % MALLOC_MAX_SIZE;
 	        	*(pointer + index) = memory_alloc(size);
            		printf("%d\t%p\n",size,*(pointer +index));
	    	    }
                    printf("\nTotal memory_alloc calls :%d\n",num);
                    number = number + num;
		break;
		case 2:
            	    system("clear");
	            printf("How many memory_calloc calls u want :");
	    	    scanf("%d",&num);
            	    printf("Size\tElements\tAdress\n-----------------------------------\n");
	    	    for(index = number ; index < number+num ;index++)
	    	    {
	        	size = rand() % CALLOC_MAX_SIZE;
	    		totalElements = rand() % CALLOC_MAX_ELEMENTS ;
 	    		*(pointer + index) = memory_calloc(totalElements , size);
            		printf("%d\t%d\t\t%p\n",size,totalElements,*(pointer + index));
            	    }
                    printf("\nTotal memory_calloc calls :%d\n",num);
                    number = number + num;
		break;
                default:
		    system("clear");
		    printf("\nWrong Choice !!!");
                break;
	    }	
	break;

  	case 2:
	    system("clear");
            do
            {
	        printf("Out of %d allocated memories how many you want to free :",number);
 		scanf("%d",&numFree);
	    }while(numFree > number || numFree <= 0);
	    printf("Number\tAddress\n-----------------\n");
	    for(index = number-1 ; index >= (number - numFree) ;index--)
	    {
		printf("%d\t%p\n",index,*(pointer +index));
                if(NULL != *(pointer +index))
	            memory_free(*(pointer +index));
	    }
            printf("\nTotal memory_free calls :%d\n",numFree);
	    number=number-numFree;
	break;

	case 3:
	    system("clear");
	    do
            {
	        printf("Out of %d allocated memories how many you want to reallocate :",number);
 		scanf("%d",&numRealloc);
	    }while(numRealloc > number || numRealloc <= 0);
            printf("Previous_Address\tNew_SIZE\tNew_Adress\n----------------------------------------------------\n");
            for(index = number-1 ; index >= (number - numRealloc) ;index--)
            {
                size=rand() % REALLOC_MAX_SIZE;
		previousAddress = *(pointer + index);
 	        *(pointer + index)=memory_realloc(*(pointer + index),size);
            	printf("%p\t\t%d\t\t%p\n",previousAddress,size,*(pointer + index));
            }
            printf("\nTotal memory_realloc calls :%d\n",numRealloc);
	break;
	case 4:
            system("clear");
	    block_information();
	break;
	case 5:
            system("clear");
	    for(index = 0 ; index < number ; index++)
    	    {
                if(NULL != *(pointer +index))
 		    memory_free(*(pointer + index));
    	    }
            number = 0;
        break;
        default:
            system("clear");
	    printf("\nWrong Choice !!!!!!");
 	break;
    }
    printf("\nPress y to continue :");
    scanf(" %c",&choice);
    }while(choice == 'y' || choice == 'Y');
    return 0;
}
Esempio n. 4
0
void* EPLIB_calloc(size_t num, size_t elem_size)
{
    return memory_calloc(num, elem_size);
}