Directory Image
This website uses cookies to improve user experience. By using our website you consent to all cookies in accordance with our Privacy Policy.

The use of multi threading technology in iOS development

Author: Subhashree Infocampus
by Subhashree Infocampus
Posted: Nov 13, 2017

Process and string

To utilize numerous strings, most importantly need to comprehend these 2 ideas of process and string. Here I just said once.

The purported procedure relating to the application is a program, is in charge of the memory for applications to utilize, however the procedure isn't performing assignments (guidelines). A procedure contains no less than one string, the string is the stream of program execution.

  • The iOS program is begun, to make a procedure in the meantime, will begin a string, the string is known as the fundamental string
  • Each process in the framework has its own autonomous virtual memory space, and different strings inside a similar procedure is shared process memory space
  • Every time a string is made, it costs a specific measure of memory and CPU time
  • When numerous strings of similar assets when the need to focus on string security issues

Application and consideration matters of multi string

The tedious, surveying or simultaneous request higher assignments to different strings to execute, and by the principle string is in charge of refreshing the interface will make the application more familiar, client encounter better, for example, organize ask for, playing the amusement mood melodies.

  • Thread isn't over the top
  • The principle string stack size of iOS is 1M
  • From the start of the second strings are 512KB
  • These qualities can't be changed by the compiler switches or string API work

Note: the refresh of the UI interface, intelligent occasion amongst interface and the client must be prepared in the fundamental string.

The multi string innovation of iOS

The strategy for multi string 1.NSObject exemplification of NSThread (comparing to a NSThread protest a string)

  • To open a foundation string to play out the errand
  • void)performSelectorInBackground:(SEL)aSelector withObject:(id)arg
  • Method the principle string notice in a foundation string to play out the errand
  • void)performSelectorOnMainThread:(SEL)aSelector withObject:(id)arg waitUntilDone:(BOOL)wait;
  • Get the string data

[NSThread currentThread];

  • Thread to rest

[NSThread sleepForTimeInterval:1.0f];

Incite:

  • The performSelectorInBackground technique is executed in the principle string, and the strategy selector determined is in a foundation string
  • Although the utilization of performSelectorInBackground technique call errand can refresh the UI interface, however in the real improvement, identified with the UI interface of the refresh operation, or to utilize the performSelectorOnMainThread strategy, stuck in an unfortunate situation

Note:

  • Memory administration is essential for the multi string
  • Objective-C can be utilized with @autoreleasepool memory assets when required, and asset recuperation
  • Each string needs the @autoreleasepool, or there may be a memory spill

2.NSThread

  • Create a string strategy:
  1. void)detachNewThreadSelector:(SEL)selector toTarget:(id)target withObject:(id)argument;
  2. id)initWithTarget:(id)target selector:(SEL)selector object:(id)argument;
  • Explanation of parameters:
  • selector: Methods of string execution, there can be just a single parameter, can't restore an esteem
  • focus on: The protest selector message transmission
  • contention: Transmission to the main parameter target, can likewise be nil

3.NSOperation/NSOperationQueue

  • Two subclasses of NSOperation
  1. NSInvocationOperation
  2. NSBlockOperation
  • Working standard:

1 utilizing the NSOperation bundle to play out an activity

The 2 will make great NSOperation protest in NSOperationQueue

3 begin the OperationQueue to begin another string to play out the operation in the line

  • Matters requiring consideration:

1 when utilizing various strings as a rule requires the quantity of simultaneous strings of control, on the grounds that the strings expends framework assets, running an excessive number of strings, the framework will back off

The quantity of strings utilizing the accompanying technique can control 2 simultaneous:

  • void)setMaxConcurrentOperationCount:(NSInteger)cnt;

3 utilizing addDependency to set up the conditions between operations, the request of execution set operation

The above system reliance, just an and B operations have been executed, will execute C.

4.GCD

  • GCD line:

1 worldwide line: all additional to the rundown of errands are executed simultaneously (may open a multi string)

dispatch_queue_t line = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);

2 serial line: all add to the serial line of errands are executed consecutively (may just open a string)

dispatch_queue_t line = dispatch_queue_create("myQueue", DISPATCH_QUEUE_SERIAL);

3 the recorded: all additional to the rundown of errands are executed on the principle string

dispatch_get_main_queue();

  • Asynchronous operation
  • The dispatch_async mission in the other string, will open another string
  • Asynchronous strategy can't decide the execution request of errands
  • p>
•Synchronous operation

  • Dispatch_sync when the present string to execute an errand, another string isn't open
  • Synchronous operation and line free
  • Synchronization technique will be executed in succession, the request of execution can choose the errand
  • Update the interface of UI, it is best to utilize synchronization technique

Note: synchronous or nonconcurrent, contingent upon the technique name (does not influence the impact of segment, the worldwide line, serial line).

Visit http://infocampus.co.in/ios-training-in-bangalore.html

About the Author

First Enquiry will help to get best Web Designing Classes In Marathahalli Bangalore. First enquiry provides the information about Web Designing Classes In Marathahalli Bangalore with review.

Rate this Article
Leave a Comment
Author Thumbnail
I Agree:
Comment 
Pictures
Author: Subhashree Infocampus

Subhashree Infocampus

Member since: Aug 08, 2017
Published articles: 34

Related Articles