ve ben bu oluştururum nasıl:Davranış: uzunluk: freeWhenDone:
void *buffer = malloc(length);
// initialize buffer content
NSData *sharedData = [[NSData alloc] initWithBytesNoCopy:buffer length:length freeWhenDone:YES]
Ya bir oluşturduktan sonra ben buffer
değiştirmek durumunda ne NSData ondan? NSData, buffer
'a yaptığım değişikliği yansıtıyor mu?
buffer
'u değiştirmek istediğimde sharedData
'un dealloc alamayacağını garanti edebilirim.
Bu
Aslında kullanmak istiyorum nasıl:void *my_alloc(CFIndex allocSize, CFOptionFlags hint, void *info) {return NULL;}
void my_dealloc(void *ptr, void *info) {
mach_vm_deallocate(mach_task_self(), (mach_vm_address_t)ptr, (size_t)info);
}
size_t length = //some number
mach_vm_address_t buffer;
mach_vm_allocate(mach_task_self(), &buffer, length, VM_FLAGS_ANYWHERE);
// do something to buffer, for example pass to other process using mach RPC and expect other process will modify the content
CFAllocatorContext context = {0, (void *)length, NULL, NULL, NULL, my_alloc, NULL, my_dealloc, NULL};
CFAllocatorRef allocator = CFAllocatorCreate(NULL, &context);
CFDataCreateWithBytesNoCopy(NULL, (const UInt8 *)buffer, length, allocator);