void clear_secret(char *secret, size_t len)
However, note that . On any decent compiler, calling memset with a zero argument will be inlined and optimized into the exact same assembly as bzero . For instance: ft-bzero
The critical differences are:
However, there is a catch. Compilers are smart. If you call ft_bzero on a buffer and then free it, the compiler might optimize away the bzero call because it seems "unnecessary" (dead store elimination). Compilers are smart
For students of the renowned École 42 curriculum, or those undertaking similar rigorous re-implementation projects (commonly referred to as "librft" or "libft"), the function ft-bzero is often one of the first hurdles encountered. It represents a rite of passage: moving from using built-in functions to understanding—and rewriting—the machinery that makes programs run. It represents a rite of passage: moving from
| Implementation | Time for 1 GB (approx) | Observations | | :--- | :--- | :--- | | Naive ft_bzero (byte loop) | ~500 ms | Pinned at 2 GB/s; limited by store-forwarding stalls. | | Word-wise ft_bzero (8-byte) | ~80 ms | ~12 GB/s; memory bandwidth becomes the limit. | | memset (glibc with AVX2) | ~30 ms | ~33 GB/s; uses vector registers (ymm) for 32-byte writes. | | memset (libc with ERMSB) | ~25 ms | Uses rep stosb microcode optimizations. |
The function is a common assignment for students in the curriculum, specifically within the