※追記日時降順
- macOS Ventura 13.x での変更を反映
- 「環境設定…」を「設定…」に変更(Application)
- 資料を整備
- macOS Monterey 12.x での変更を反映
- 「テキストの置き換え」を「テキストの置換」に変更(Substitutions)
The libdispatch is one of the most misused API due to the way it was presented to us when it was introduced and for many years after that, and due to the confusing documentation and API. This page is a compilation of important things to know if you're going to use this library. Many references are available at the end of this document pointing to comments from Apple's very own libdispatch maintainer (Pierre Habouzit).
My take-aways are:
You should create very few, long-lived, well-defined queues. These queues should be seen as execution contexts in your program (gui, background work, ...) that benefit from executing in parallel. An important thing to note is that if these queues are all active at once, you will get as many threads running. In most apps, you probably do not need to create more than 3 or 4 queues.
Go serial first, and as you find performance bottle necks, measure why, and if concurrency helps, apply with care, always validating under system pressure. Reuse
SUPPORTED_PLATFORMS = macosx iphoneos iphonesimulator appletvos appletvsimulator watchos watchsimulator | |
VALID_ARCHS[sdk=iphone*] = arm64 armv7 armv7s | |
VALID_ARCHS[sdk=macosx*] = i386 x86_64 | |
LD_RUNPATH_SEARCH_PATHS[sdk=iphone*] = @executable_path/Frameworks @loader_path/Frameworks | |
LD_RUNPATH_SEARCH_PATHS[sdk=appletv*] = @executable_path/Frameworks @loader_path/Frameworks | |
LD_RUNPATH_SEARCH_PATHS[sdk=watch*] = @executable_path/Frameworks @loader_path/Frameworks | |
LD_RUNPATH_SEARCH_PATHS[sdk=macosx*] = @executable_path/../Frameworks @loader_path/Frameworks |
NSString *const PSPDFApplicationDidReceiveMemoryWarningNotification = @"PSPDFApplicationDidReceiveMemoryWarningNotification"; | |
// Test with sudo memory_pressure -l critical. Don't forget to re-set afterwards! | |
__attribute__((constructor)) static void PSPDFInstallLowMemoryNotificationWarningMac(void) { | |
static dispatch_source_t source; | |
static dispatch_once_t onceToken; | |
dispatch_once(&onceToken, ^{ | |
source = dispatch_source_create(DISPATCH_SOURCE_TYPE_MEMORYPRESSURE, 0, DISPATCH_MEMORYPRESSURE_WARN|DISPATCH_MEMORYPRESSURE_CRITICAL, dispatch_get_main_queue()); | |
dispatch_source_set_event_handler(source, ^{ | |
dispatch_source_memorypressure_flags_t pressureLevel = dispatch_source_get_data(source); |