Friday, 6 September 2013

What is the best approach for Core Data with a cvdisplaylink?

What is the best approach for Core Data with a cvdisplaylink?

first question here. Long time developer but new to xcode.
I'm writing a document based app using core data for osx. The app consists
of a gui to edit the core data objects through bindings and nsarray
controllers using entites. A cvdisplaylink thread should render the model
as represented in the gui, different representations of entites could
appear in different windows.
In the displaylink thread, entites have various properties set relevant
for opengl, textures and buffers are set, and need to be able to be passed
to other enties, they're only relevant at runtime and completely derived
from the properties of the entity. However, these transient properties
should persist as much as possible, as they're used to improve opengl
performance.
I've been reading the documents on concurrency with core data, and read
many questions and answers on this site regarding setting multiple
contexts for seperate threads, but all seem to deal with bulk data loading
in a background thread, and usually rely on a save notification. As I want
to represent the current state in the gui, this isn't suitable. I'm also
unclear as to how I should setup a nsmanagedobectcontext hierarchy
suitable for my purpose.
It would be ideal to just have a single nsmanegedobjectcontext, and tell
the main thread to do a render from the cvdisplaylink callback, but I've
read places this can cause frames to be dropped, something I really want
to avoid.
So if I go for a multi context setup, what would be the best way to set it
up so that the cvdisplaylink thread has access to the current data, and
still allow the opengl variables I set to persist?
One paragraph on the concurrecny with core data guide worries me greatly
"If you choose to use concurrency with Core Data, you also need to
consider the application environment. For the most part, AppKit and UIKit
are not thread safe; in particular, on OS X Cocoa bindings and controllers
are not thread safe—if you are using these technologies, multi-threading
may be complex.". If it is going to be complex, it's be helpful to know
which direction to go.....
I've played around with different setups of multiple
nsmanagedobjectcontexts in various configurations, but had little luck, if
someone could point me in the right direction, it would be great.

No comments:

Post a Comment