Manpage Monday: memset_pattern(3)

2010-09-06 07:41:36 UTC

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.

2 Responses to “Manpage Monday: memset_pattern(3)”

  1. Catfish_Man Says:

    As might be expected, memset_pattern has vectorized asm implementations on the commpage for all supported architectures (G4, G5, x86, x86_64, and ARM).

  2. Allan Says:

    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.

Leave a Reply

Do not delete the second sentence.