t_header *do_malloc(size_t taille, t_header *pstart_free, t_header *pstart_alloc) { t_header *cur; unsigned int nbblocks; nbblocks = get_real_size(taille); if ((cur = find_freeblock(nbblocks, pstart_free)) == NULL) { if (ask_memory(nbblocks) == 0) return (NULL); } else { cur->size = get_real_size(taille); add_list_alloc(pstart_alloc, cur); return ((t_header *)cur + 1); } if ((cur = find_freeblock(nbblocks, pstart_free)) == NULL) return (NULL); else { cur->size = get_real_size(taille); add_list_alloc(pstart_alloc, cur); return ((t_header *)cur + 1); } }
block_datastr *blkdev_write_block(UID id,char *data) { int size; char *copy_ptr; block_datastr *ret; block_datastr *bp; char *temp; int i=0; ret = bp = find_freeblock(); // get free block pointer printf("%x\n", ret); size = get_datasize(data); // get size of data printf("%d\n", size); while(size > 0){ if(bcb.blocksleft <= 0) { printf("No have empty block"); return NULL; } bp->next = (unsigned int)(bp->next)|(0x1); // check block to be used if(size > BLOCK_SIZE) { MemCpy(bp->data, data, BLOCK_SIZE); bp->next = (unsigned int)(bp->next)|(unsigned int)find_freeblock(); bp = (unsigned int)(bp->next)&0xFFFFFFFE; } else { MemCpy(bp->data, data, size); } size = size - BLOCK_SIZE; bcb.blocksleft--; } return ret; }
void *mymalloc(size_t taille) { unsigned int nbblocks; t_header *cur; /* my_putstr("############## MALLOC ######### taille"); my_put_nbr(taille); my_putchar('\n');*/ cpt++; nbblocks = get_real_size(taille); if (taille <= 0) return (NULL); if (!start) { start_free.next = &start_free; start_free.size = 0; start_alloc.next = &start_alloc; start_alloc.size = 0; start = 1; min_addr = sbrk(0); } if ((cur = find_freeblock(nbblocks)) == NULL) { if (ask_memory(nbblocks) == 0) return (NULL); } else { cur->size = get_real_size(taille); add_list_alloc(&start_alloc, cur); return ((t_header *)cur + 1); } if ((cur = find_freeblock(nbblocks)) == NULL) return (NULL); else { add_list_alloc(&start_alloc, cur); cur->size = get_real_size(taille); return ((t_header *)cur + 1); } }