這是正確的方法嗎?如何將dispatch_data_t轉換爲NSData?
// 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。這是否意味着釋放緩衝區是我的責任?
這僅適用於iOS 7/10.9 – 2013-10-29 22:33:10
Thx,是的,我添加了發行說明鏈接。 – catlan 2013-10-29 23:24:45
什麼是他人的解決方案? – 2016-05-18 12:21:54