を使用してNSThread
、スタック サイズを次のように設定しています。
thread=[[NSThread alloc]initWithTarget:self selector:@selector(fibnocciForLoop) object:nil];
[thread setStackSize:12];
[thread start];
for のAppleドキュメントに書かれているように-[NSThread setStackSize:]
:
ディスカッション
スレッドを開始する前に、このメソッドを呼び出す必要があります。スレッドの開始後にスタック サイズを設定すると、属性のサイズ (stackSize メソッドによって反映される) が変更されますが、スレッド用に確保されている実際のページ数には影響しません。
しかし、後でデバッガーでスタック サイズを確認すると、設定した値が得られません。
print (int)[thread stackSize]
$1 = 524288
My question is why does the setStackSize:
method exist if it does nothing?
Please let me know where I am wrong, or whether the API for setStackSize:
is not of any use?
EDIT: 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:
thread=[[NSThread alloc]initWithTarget:self
selector:@selector(fibnocciForLoop) object:nil];
[thread setStackSize:12*4096];//4K=4096
[thread start];
EXTENSION OF THIS QUESTION:
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.
I want to know its exact purpose in NSThread?
Thanks!