// // Buffer.m // ConcurrentPerformTest // // Created by Eric Hovhannisyan on 02.09.22. // #import "Buffer.h" #include @implementation Buffer size_t cBuffer[5000]; - (instancetype)initWithArray:(NSArray *)array { self = [super init]; if (self) { // Uncomment to fix crash // NSNumber *a = array[0]; mapTo(cBuffer, [&](size_t i) { cBuffer[i] = (size_t)array[i]; std::cout << i << std::endl; }); } return self; } void mapTo(size_t *destBuffer, std::function mapper) { auto ptr = workFunc; dispatch_apply_f(5000, DISPATCH_APPLY_AUTO, &mapper, ptr); } void workFunc(void *ctx, size_t iteration) { auto mapper = static_cast*>(ctx); (*mapper)(iteration); } @end