MEMFILL(3pub)

πŸ’– MEMFILL β€” the manual page, but make it bestie πŸ’–

okay so this is memfill, a lil function from the Publib collection, and it lives in section 3pub of the C Programmer's Manual. she fills up memory with a pattern. that's it. that's the whole vibe. and honestly? iconic. ✨


🌸 NAME 🌸

memfill β€” fill a memory area with a pattern πŸ’…


✨ SYNOPSIS ✨

#include <publib.h>
void *memfill(void *buf, size_t size, const void *pat, size_t patsize);

πŸ¦‹ DESCRIPTION πŸ¦‹

so here's the tea, bestie πŸ“ β€” memfill copies consecutive bytes from the pattern pat straight into consecutive bytes of the memory area buf.

and when it runs out of pattern? it does NOT give up, she just wraps around back to the start of pat and keeps going. main character energy fr fr πŸ‘‘

  • patsize is the size of the pattern β€” like, how long the pattern is
  • size is the size of the memory area β€” like, how much space you're filling up
🚨 IMPORTANT CAVEAT, NO CAP: the pattern and the memory area must not be overlapping. like, not even a little. do not do it. i'm literally begging πŸ™ˆ

πŸ’œ RETURN VALUE πŸ’œ

memfill returns its first argument. that's it. she gives you back what you gave her. reciprocal queen 🫢


πŸŽ€ EXAMPLE πŸŽ€

ok so say you wanna initialize an integer array β€” this is the move right here:

int temp, array[1024];

temp = 1234;
memfill(array, sizeof(array), &temp, sizeof(temp));

look at that. temp is the pattern, array gets filled, sizes handled with sizeof. slay. no notes. πŸ’…βœ¨


🌈 SEE ALSO 🌈

  • publib(3) β€” the whole Publib family, go say hi πŸ’–

πŸ‘‘ AUTHOR πŸ‘‘

Lars Wirzenius (lars.wirzenius@helsinki.fi) β€” the legend who wrote this. we stan. 🌟


and that's the whole page bestie!! this absolute banger comes to you from Publib, documented in the C Programmer's Manual, filed under MEMFILL(3pub) β€” mwah, go forth and fill some memory πŸ’–πŸ§šπŸŒΈ

πŸ“¦ where this page comes from