Manpage Monday: memset_pattern(3)
From the manpage:
void memset_pattern4(void *b, const void *pattern4, size_t len); void memset_pattern8(void *b, const void *pattern8, size_t len); void memset_pattern16(void *b, const void *pattern16, size_t len);
These are analogous to
memset()
, except that they fill memory with a replicated pattern either 4, 8, or 16 bytes long.
Handy if you want to scribble 0xdeadbeef (or any other value of your choice) over something.
As noted in the manpage, these functions require Mac OS X 10.5 or later. I don’t know about iOS.
September 6th, 2010 at 08:06:53
As might be expected, memset_pattern has vectorized asm implementations on the commpage for all supported architectures (G4, G5, x86, x86_64, and ARM).
November 3rd, 2010 at 09:10:02
Back in OS9 days, there was a trick where you would set unused allocated memory to a certain invalid pattern (rather than zeroing out) so that Handle initializations (pointers to pointers, or System-managed pointers) would immediately error out and help point out (ahem) code issues, rather than return null pointers or bad references. Or something like that, it’s been a long time.