int main(void) { char *tab1; char *tab2; char *tab3; char *tab4; char *tab5; char *tab6; char *tab7; tab1 = malloc(10); tab2 = malloc(32); tab2 = malloc(32); tab3 = malloc(12); tab4 = malloc(5000); tab5 = malloc(32); tab6 = malloc(32); tab7 = malloc(6000); show_alloc_mem(); free(tab5); free(tab4); tab7 = malloc(7000); show_alloc_mem(); realloc(tab2, 45); realloc(tab1, 46); show_alloc_mem(); return (0); }
void *malloc(unsigned int taille) { t_blk *new_blk; unsigned char psize; char val[33]; taille += sizeof(t_blk); sup_power(&taille, &psize); if (!(new_blk = get_available(psize))) { new_blk = sbrk(taille); add_blk(new_blk, psize); } else { new_blk->is_available = 0; } my_putstr("taille :\n"); my_putnbr(psize); my_putchar('\n'); conv_10_to_16(new_blk, val); my_putstr(val); my_putchar('\n'); show_alloc_mem(); return (new_blk + 1); }
void *malloc(size_t size) { size_t i; size_t real_size; i = 0; if (size > MAX_LARGE) return (NULL); ft_printf(C_YELLOW"\nNEW MALLOC:\t\tsize = %d\t"C_RESET, size); while (i < 3) { if (size <= (g_zone.zone[i].r_size)) { real_size = g_zone.zone[i].q_size; real_size = (size % real_size == 0 ? size : ((size / real_size) + 1) * real_size); ft_printf("TYPE: %s\tC_SIZE: %d\tM_SIZE: %d\n", g_zone.zone[i].name, CHUNK_SIZE, META_SIZE); { show_alloc_mem(); return (g_zone.zone[i].ft_malloc(real_size, &g_zone.zone[i])); } } i++; } return (NULL); }
int main() { malloc(1024); malloc(1024 * 32); malloc(1024 * 1024); malloc(1024 * 1024 * 16); malloc(1024 * 1024 * 128); show_alloc_mem(); return (0); }
int main() { char *addr; write(1, "start\n", 7); addr = malloc(100); write(1, "end\n", 5); show_alloc_mem(); return (0); }
int main(int ac, char *av[]) { int i; i = 0; printf("---120 x malloc(%d)---\n", TINY_BLOCK_MAX_SIZE-1); while (i < 120) { malloc(TINY_BLOCK_MAX_SIZE-1); i++; } show_alloc_mem(); return (0); }
void test() { size_t i; char *str; i = 0; str = NULL; while (i < 1000) { str = malloc(i); str = realloc(str, i / 2); i++; } show_alloc_mem(); }
void tests_complet_map_tiny(int tiny) { FILE *fd; int i; int value; unsigned char **tab; printf("\033[34;01mTESTS_COMPLET_MAP_TINY\033[00m\n"); fd = fopen("tmp/tests_complet_map_tiny.check", "w+"); tab = (unsigned char **)malloc(sizeof(unsigned char *) * 100); if (!tab) { fprintf(fd, "\033[31;01mError malloc 100 * 'sizeof(unsigned char *)'\033[00m\n"); return ; } i = 0; value = rand() % tiny + 1; while (i < 100) { if (i == 42) value = 1; fprintf(fd, "value: %d, i: %d\n", value, i); tab[i] = malloc(sizeof(char) * (value)); if (!tab[i]) fprintf(fd, "\033[31;01mError malloc size %d, nbr alloc: %d\033[00m\n", value, i); if (value != 1) { memset(tab[i], 'b', value); tab[i][value - 1] = '\0'; tab[i][0] = 'a'; tab[i][value - 2] = 'a'; } i++; value = rand() % tiny + 1; } i = 0; while (i < 100) { fprintf(fd, "Alloc num: %d: %s\n", i, tab[i]); free(tab[i]); i++; } free(tab); printf("\033[33;01mshow alloc mem doit montrer qu'il y a aucune allocation en cours:\033[00m\n"); show_alloc_mem(); fclose(fd); }
int main(void) { pthread_t thr; void *res; int s; s = pthread_create(&thr, NULL, &thread_func, NULL); if (s != 0) handle_error_en(s, "pthread_create"); char *p; size_t i = 1000; p = 0; while (i < 4000) { p = realloc(p, i); if (p) p[0] = 42; else { puts("no"); exit(1); } i++; } printf("main(): sending cancellation request\n"); s = pthread_cancel(thr); if (s != 0) handle_error_en(s, "pthread_cancel"); s = pthread_join(thr, &res); if (s != 0) handle_error_en(s, "pthread_join"); if (res == PTHREAD_CANCELED) printf("main(): thread was canceled\n"); else printf("main(): thread wasn't canceled (shouldn't happen!)\n"); show_alloc_mem(); exit(EXIT_SUCCESS); }