Note that there are some explanatory texts on larger screens.

plurals
  1. PONSThread setStackSize not setting the size of thread
    text
    copied!<p>I am using an <code>NSThread</code> and setting the stack size for it as follows:</p> <pre><code>thread=[[NSThread alloc]initWithTarget:self selector:@selector(fibnocciForLoop) object:nil]; [thread setStackSize:12]; [thread start]; </code></pre> <p>As written Apple docs for for <a href="https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSThread_Class/Reference/Reference.html#//apple_ref/doc/uid/20000311-SW9" rel="nofollow"><code>-[NSThread setStackSize:]</code></a>:</p> <blockquote> <p><strong>Discussion</strong><br> You must call this method before starting your thread. Setting the stack size after the thread has started changes the attribute size (which is reflected by the stackSize method), but it does not affect the actual number of pages set aside for the thread.</p> </blockquote> <p>But when I check the stack size later in the debugger I don't get the value I set:</p> <pre><code>print (int)[thread stackSize] $1 = 524288 </code></pre> <p>My question is why does the <code>setStackSize:</code> method exist if it does nothing?</p> <p>Please let me know where I am wrong, or whether the API for <code>setStackSize:</code> is not of any use? </p> <p><strong>EDIT:</strong> Refer to Answer by @Josh Caswell for this question, i missed the K in 4K , and hence the above code will work fine as under:</p> <pre><code> thread=[[NSThread alloc]initWithTarget:self selector:@selector(fibnocciForLoop) object:nil]; [thread setStackSize:12*4096];//4K=4096 [thread start]; </code></pre> <p><em><strong>EXTENSION OF THIS QUESTION:</em></strong></p> <p>Can someone kindly explain as to why Apple gave this method setStackSize, and how and when to use this particular method, because it requires a lot of calculations for the user to calculate as to how many bytes are/will be used. </p> <p><strong>I want to know its exact purpose in NSThread?</strong></p> <p>Thanks! </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload