简体   繁体   中英

Create autorelease pool on posix thread

I'm using a GTMLogger functions for formatted logging in my application. This application creates real-time posix threads (audio packets processing). Sometimes we need to perform a logging from within these non-Cocoa threads. GTMLogger creates autoreleased objects and I thought to put an @autoreleasepool block on GTMLogger calls in the function, that logs from non-Cocoa threads, but I'm afraid it will affect the performance.

My question is - can I somehow create the autorelease pool and associate it with the current posix thread, so the pool is created only once per thread and not each time the log function is called?

Thanks in advance

Under ARC, using @autoreleasepool is quite fast. If you're concerned about performance in there, I would worry much more about avoiding unnecessary logging calls in the first place than about the autorelease pool.

You can't generally create a pool that is associated with "the thread" if the thread is long-lived. You need to to drain the pool periodically, and that won't happen if you just bracket the entire thread main function in an @autoreleasepool{} or anything similar to that.

好吧,如果您无法控制线程的主要功能,那么我想您最好的办法就是将自动释放池放置在该库“调出”到您控制的代码中。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM