I'm using an API that takes a CFData
object, and I need to generate the data on the fly, which is a time consuming operation. The CFData
is read by the consumer in a random, non-contiguous manner, and it rarely actually needs the entire length of the data -- it just needs certain random pieces of it.
I would like to improve performance by only actually generating the bits that are requested by the consumer, as they are requested.
Is there any way to subclass CFData
/NSData
such that I would get callbacks as data chunks are being read and generate them on the fly?
Update: Unfortunately the consumer is 3rd party code and so other classes aren't an option, unless they're somehow magically compatible with CFData
.
I don't think you're going to like the answers you get here. You seem to be cornered with respect to options.
CFData
is a CoreFoundation C-type and doesn't have a runtime to play withCFData
wraps a void *
to data, but has some padding at the beginning (likely a struct) that'll be difficult to mimic if you tried to create a CFData
proxy objectIt's going to be very difficult to accomplish what you want without some clever, un-maintainable, and overall dangerous symbol hackery I won't even bother to get into.