First of all, but forget the address.
pointer in array int array[3] = {11,22,33}
&array[0] can be seen as a pointer to array[0], pointing to Data of type int (4 bytes of data)
Array can be seen as a pointer: point to array[0], same price and &array[0]
&array can be seen as a pointer to array arrays, array[3] is 12 bytes of data
Use of static
Modifies a local variable, modifying the life cycle
Static modified local variables, initialized only once during the entire program run, and only one copy of memory
Static modified local variable, and no scope changed
Modifies a global variable, modifying a scope
A global variable that is not modified by the static, any file in the project, can be accessed
Static modified global variable, accessed only in the current file
The difference between const and define use
Define modified variable does not specify type, const specified type
Defien modified variables each time a reference to the memory, while the const only one copy of memory
If the modified code fragment is suitable for use with define, if the modifier is a variable suitable for use with a const
The connection and difference between Ismemberofclass and Iskindofclass
Contact: Both can detect whether an object is a member of a class
The difference: Iskindofclass not only determines whether an object is a member of a class, but also determines if an object is a member of a class derived from that class, and Ismemberofclass can only do the former.
The difference between assign,retain,copy
Assign: general assignment, commonly used for basic data types, common delegate design patterns, to prevent circular references. (We call it weak references)
Retain: Gets the ownership of the object, and the reference count is added 1 based on the original count.
Copy: It is generally assumed that a new memory space has been reopened in memory to store new objects, and the original object is two different addresses, with reference counts of 1 respectively. But when the copy object is an immutable object, then copy is the equivalent of retain. Because, this saves memory space
Nil, the difference between Nil,null and NSNull
Nil pointer to an object is empty, as defined in objc.h: nsstring *name = nil;
Nil pointer to a class is empty and is defined as follows: Class aclass = Nil;
Null pointer to type C is empty, for example: Int*pint = NULL;
NSNull is a class in objective-c, except that there is a null in the name and more for an object with a null value in the collection (nsarray,nsdictionary)
Multithreading
Multithreading principle
At the same time, the CPU can only handle 1 threads, multithreading concurrent execution, in fact, the CPU is quickly dispatched between multiple threads
Threads are a lot of harm: the CPU is dispatched between n multiple threads, the CPU is exhausted and consumes a lot of CPU resources
The frequency at which each thread is scheduled to execute is reduced (thread execution efficiency is reduced)
Multi-threaded Implementation scheme
Pthread a set of common multi-threaded API for Unix/linux/windows and other systems, cross-platform \ Portable, difficult to use, C language, programmer management life cycle, the project almost no
Nsthread uses more object-oriented, easy-to-use, direct manipulation, OC language, programmer management Lifecycle, and occasional use in projects
GCD is designed to replace Nsthread and other threading technologies, make full use of the device's multicore, C language, and automatically manage the lifecycle, often using nsoperation based GCD (the bottom is gcd), more simple and useful features than GCD, using more object-oriented, OC language, Automatically manage lifecycles, frequently used in projects
The security hidden trouble of multithreading
Resource sharing, 1 blocks of resources may be shared by multiple threads, such as multiple threads accessing the same object, the same variable, the same file
Security hazard Resolution-Mutex
Mutex uses format @synchronized (lock object) {//code to be locked}
Advantages and disadvantages of mutual exclusion lock
Advantages: It can effectively prevent the data security problem caused by multi-thread snatch resource
Cons: Consumes a lot of CPU resources
Related jargon: Thread synchronization, multiple threads executing on the same line (performing tasks sequentially)
Add
OC has nonatomic and atomic two choices when defining attributes
Atomic: Atomic attribute, locking for setter method (default is atomic), thread-safe, requires a lot of resources
Nonatomic: Non-atomic attribute, no lock-setter method, non-thread-safe, suitable for small memory mobile devices
GCD
Full name Grand Central Dispatch "Awesome Hub Scheduler"
Multi-core parallel operation, automatic management of thread life cycle (create thread, dispatch task, destroy Task)
CGD 2 Core Concepts:
What the task does, and the queue is used to hold the task
Add a task to the queue, CGD will automatically take the task out of the queue and put it in the corresponding thread.
Primary impact of synchronous and asynchronous: Can I open a new thread
Sync: Perform tasks only in the current thread, without the ability to open new threads
Async: Can perform tasks in a new thread, with the ability to open new threads
The difference and connection between TCP and UDP
TCP is the Transport Control layer protocol for connection-oriented, reliable, point-to-point communication
UDP for User Datagram Protocol, non-connected unreliable point-to-multipoint communication
TCP focuses on reliable transmission, UDP focuses on fast transmission
Network Layer Protocol
Application layer:
User interface, application program;
Application typical equipment: gateway;
Typical protocols, standards, and Applications: TELNET, FTP, HTTP
Presentation layer:
Data representation, compression, and encryption presentation
Typical device: Gateway
Typical protocols, standards, and Applications: ASCLL, PICT, TIFF, jpeg| MPEG
The presentation layer is equivalent to a representation of something, representing some of the protocols that are MPEG than slices, sounds, and videos.
Session Layer:
The establishment and completion of the session;
Typical equipment: gateway;
Typical protocols, standards, and Applications: RPC, SQL, NFS, X WINDOWS, ASP
Transport Layer:
Main function: End-to-end control transport;
Typical equipment: gateway;
Typical protocols, standards, and Applications: TCP, UDP, SPX
Network layer:
Main functions: routing, addressing network;
Typical equipment: routers;
Typical protocols, standards, and Applications: IP, IPX, APPLETALK, ICMP;
Data Link Layer:
Main function: To ensure error-free negligence link data link;
Typical equipment: switch, Network bridge, network card;
Typical protocols, standards and applications: 802.2, 802.3ATM, HDLC, FRAME RELAY;
Physical Layer:
Main function: Transmit bit stream physical;
Typical devices: hubs, repeaters
Typical protocols, standards, and Applications: v.35, eia/tia-232.
TCP Three-time handshake
First handshake: The client sends a SYN packet (SYN=J) to the server and enters the Syn_send state, waiting for the server to confirm;
Second handshake: The server receives the SYN packet, must confirm the customer's SYN (ACK=J+1), simultaneously also sends a SYN packet, namely the Syn+ack packet, at this time the server enters the SYN+RECV state;
Third handshake: The client receives the server's Syn+ack packet, sends the acknowledgment packet ack (ACK=K+1) to the server, and the client and server enter the established state, completing three times.
Socket links and HTTP links
The HTTP protocol is TCP-based and is an application-layer protocol that primarily addresses how data is packaged. Socket is the TCP/IP protocol encapsulation, the socket itself is not a protocol, but a call interface (API), through the socket, we can use the TCP/IP protocol. HTTP connection: Short connection, the client sends a request to the server, the server responds after the connection disconnects, save resources. The server cannot proactively respond to the client (unless using HTTP long connection technology), the iphone mainly uses class Nsurlconnection.
Socket connection: Long connection, the client and the server directly using the socket to connect, there is no provision for disconnection after the connection, so the client and server segments remain connected channels, both sides can actively send data, generally more for the game. The socket default connection time-out is 30 seconds, and the default size is 8K (understood as a packet size).
HTTP protocol, the difference between get and post
POST request: The parameter is placed in the request data area, is more secure relative to the GET request, and has no limit on the data size. Place the submitted data in the package body of the HTTP packet.
GET request: The parameter is spliced after the address, there is no request data, unsafe (because all parameters are stitched behind the address), is not suitable for transferring large amounts of data (limited length, 1024 bytes).
HTTPS: The Secure Hypertext Transfer Protocol (secure hypertext Transfer Protocol), a secure communication channel based on HTTP development, for exchanging information between client computers and servers, exchanging information using Secure Sockets Layer (SSI), That is, the security version of HTTP.
Network message push
One is Apple's own notification server (APNs server), a third-party push mechanism
First, the system popup prompts the user whether to allow, when the user allows the Apple Server (APNS) to request Devicetoken, and by the Apple server sent to their own apps, their app will Devicetoken and want to push the information sent to the Apple server, Apple server sends information to app
Push message content with a total capacity of no more than 356 bytes
Loadview, Viewdidload, Viewdidunload's relationship
The first time you access Uiviewcontroller view, view is nil, and then the Loadview method is called to create the view
When the view is created, the Viewdidload method is called to initialize the interface element.
When a memory warning occurs, the system may release Uiviewcontroller view, assign the view to nil, and call the Viewdidunload method
When accessing Uiviewcontroller view again, the view has been assigned nil, so the Loadview method is called to rebuild the view
When the view is re-created, the Viewdidload method is called to initialize the interface element
The difference between load and initialize
Common:
Regardless of the developer's active use, the system will be called at most once, if the parent class and child classes are called, the parent class must be called before the subclass, in order for the application to run ahead of the creation of the appropriate environment, when used, do not rely heavily on these two methods, unless it is really necessary.
Difference:
The Load method call is premature and the operating environment is uncertain. Specifically, it is usually loaded on iOS when the app is launched, but when the load is called, there is no guarantee that all classes will be loaded and available, and that you are responsible for auto release when necessary. For the two libraries that have dependencies, the load of the dependent classes is called first. But within a library, the order of calls is indeterminate. Add
For a class, no implementation of the Load method is called, and inheritance of NSObject is not considered. The load method of a class does not specify [super Load], the parent class receives the call, and precedes the subclass. The category load will also receive calls, but in order after the main class's load call. Initialize calls are not triggered directly.
iOS Cold knowledge