objective c - Storing blocks in a c-style array -
I'm trying to start the AC array of dynamically blocks, load it, and then run them and some Can use help.
// Definitions ===================================== === === Typefief Zero (^ Morph C) (Scratchy * Scratch); @property (nanatomic) morph c __strop * morphCs; // Construction of Morph Registry ======================== Static NSMutableDictionary * morphs_; + (Zero) start {morphs_ = [[NSMUTABADADADHQ] annot]; [Methak Hydrate]; } + (Zero) hydrate {{MathC registers morph: Execute "sin": ^ (Scratchy * scratches) {AEscratches (Scratch, Sin (AESCratchpop (Scratch)); }]; } + (Zero) Register Merge: (NSString *) Name Execute: (MorphC) executed {{morphs_ setObject: for exec: key: name}; } + (Morph C) morphFromKey: (NSString *) key {return [morphs_ objectForKey: key]; } // A temporary NSMutableArray * _compiling is loading * _compiling ===== - (zero) applyTag: (NSString *) Tag stack: (stack *) stack {{_compiling addObject: [MathC morphFromKey: tag]]; } // start the C array and load with NSMutableArray == - (zero) build {_morphCs = (MorphC __strong *) malloc (_compiling.count * sizeof (MorphC)); I = 0; For (morphc morph in _compiling _morphcs [i ++] = morph; // Currently, getting a poor access here} // execute the morph ================================ == - (CGFloat) Evaluate float: (Warsi *) Wars {if (! [_ Morphs count]) back to NAN; AEScrawl variants (_scratch, vars); For (int i = 0; i & lt; [_ morphs count]; i ++) _morphcs [i] (_ scratches); Return AEScrapp (_scratch); }
I am currently getting EXC_BAD_ACCESS while creating Sea Array, but I suspect that I have many problems, I do not fully understand the __strong in morphCs definition, But the compilers complain with the outside.
Do I need to copy [copied] in one or more places?
Is anything else that I'm messing up? / P>
You can not make an array of strong codes malloc
.
Think of the words of a strong indicator: when it is declared, its value starts from zero when it is out of the scope of the variable, then it releases its current value is. Therefore, the compiler should be able to keep track of strong points so that it can carry it out. If you have strong points of unknown length, for example, it gets out of the scope, so how does the compiler know how many signs are given? This can not happen.
In the C ++ terminology, strong references are "non-POD" types - they have nonentrival constructors and destructors. Therefore, they can not be allocated with malloc
.
This is mentioned in the ARC specification:
This is not an exception, if any managed operation is performed on a __stroung or __wec object without any guarantee in it A primitive zero bit-pattern is included, or if the storage is free or reused for such an object, then the object can be assigned to a blank pointer.
In other words, you are the only way to use malloc
and free
if you guarantee that every time you call You can call malloc
after the memory of all those points that you allocated, before using them. And every time before free
you guarantee to assign zero
to each strong indicator in the array.
However, in Objective-C ++, you
In C ++
Comments
Post a Comment