From the devious mind of Rainer Brockerhoff : given a pointer + length, dynamically allocate a copy and make it autoreleased, without (directly) involving cocoa objects. One handy usage: giving a plugin a copy of some struct, but be protected against the plugin messing it up.static void *tempCopyOf(void *data,UInt32 size) { void *buffer = NULL; if (data) { buffer = malloc(size); if (buffer) { bcopy(data,buffer,size); [NSData dataWithBytesNoCopy: buffer length: size freeWhenDone: YES]; } } return (buffer); }You can get really fancy and assignbuffer
tocalloc(1, size)
if you want to give it "pass NULL to get a zero-filled buffer back" semantics.Also note this doesn't play well with garbage collection - caveat nerdor. (Thanks to Ken Ferry for that note)