这是正确的方法吗?
// convert
const void *buffer = NULL;
size_t size = 0;
dispatch_data_t new_data_file = dispatch_data_create_map(data, &buffer, &size);
if(new_data_file){ /* to avoid warning really - since dispatch_data_create_map demands we care about the return arg */}
NSData *nsdata = [[NSData alloc] initWithBytes:buffer length:size];
// use the nsdata... code removed for general purpose
// clean up
[nsdata release];
free(buffer); // warning: passing const void * to parameter of type void *
它工作正常。我主要担心的是内存泄漏。泄漏数据缓冲区并不好玩。那么 NSData、缓冲区和 dispatch_data_t new_data_file 都好吗?
从我在http://opensource.apple.com/source/libdispatch/libdispatch-187.7/dispatch/data.c上看到的内容看来,缓冲区是 DISPATCH_DATA_DESTRUCTOR_FREE。这是否意味着释放缓冲区是我的责任?