objective c - why most of the objects we create in iphone are pointers -


Why are we the most object indicators created in the iPhone? Like I create NSString * str, NSMutableDictionary * dict .. etc

short answer
Because Object-Objects can be allocated only on a heap and manipulated as pointers.

Long answer
Objective-C is required to allocate classes on the heap and tampering as a sign because polymorphism requires the use of pointers Because the indicator of the interface is always the same size, whereas different implementations of the interface can have different sizes. In C ++, anyone can use both automated (stack) and dynamic (heap) storage; However, in the former case, someone should be careful to piecemeal (when a derivative type is assigned to a base type, resulting in the object being lost from the material which makes it a derivative type instead of the base type ), And Obj-C as the only indicator eliminates these potential flaws. In addition, the stack-allocated objects can be used as a reference calculation plan Tilts, which are in Objective-C, and since stack-object objects are only in the scope in which they are created, one usually allocates the object to the heap, as well as in the form of stack-allocated values Supporting items will have marginal benefits. As a side note, I should also mention that objects in Java and C # are bound to allocate equally.


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -