stack

Disadvantages of using large variables/arrays on the stack?

百般思念 提交于 2019-12-01 18:20:00
问题 What are the disadvantages, if any, of defining large arrays or objects on the stack? Take the following example: int doStuff() { int poolOfObjects[1500]; // do stuff with the pool return 0; } Are there any performance issues with this? I've heard of stack overflow issues, but I'm assuming that this array isn't big enough for that. 回答1: Stack overflow is a problem, if the array is larger than the thread stack the call tree is very deep, or the function uses recursion In all other cases, stack

Disadvantages of using large variables/arrays on the stack?

不想你离开。 提交于 2019-12-01 18:01:31
What are the disadvantages, if any, of defining large arrays or objects on the stack? Take the following example: int doStuff() { int poolOfObjects[1500]; // do stuff with the pool return 0; } Are there any performance issues with this? I've heard of stack overflow issues, but I'm assuming that this array isn't big enough for that. Stack overflow is a problem, if the array is larger than the thread stack the call tree is very deep, or the function uses recursion In all other cases, stack allocation is a very fast and efficient way to get memory. Calling a large number of constructors and

Without using recursion how can a stack overflow exception be thrown?

落爺英雄遲暮 提交于 2019-12-01 17:48:56
Without using recursion how can a stack overflow exception be thrown? If you call enough methods, a stack overflow can occur anytime. Although, if you get stack overflow errors without using recursion, you may want to rethink how you're doing things. It's just so easy with recursion because in an infinite loop, you call a ton of methods. Since no one else has mentioned it: throw new System.StackOverflowException(); You might do this when testing or doing fault-injection. Declare an ENORMOUS array as a local variable. The following applies to Windows, but most OSs implement this in a similar

How to increase stack size in bison (and solve “memory exhausted”)

馋奶兔 提交于 2019-12-01 17:17:06
My bison-based parser started choking on some moderately sized files I've generated recently. It throws an exception about "memory exhausted." The bison man page says that this is likely due to use of right-hand recursion. Without trying to rewrite the grammar (I am on a tight deadline), I would like to simply increase the stack to get the parser to parse this file. I tried to follow the bison man page and #define YYMAXDEPTH to some number larger than the default 10000, but that didn't work. When I look at the output from bison, it seems like YYMAXDEPTH is only conditionally used when YYSTACK

Sorting large lists in Prolog: Not enough memory

烈酒焚心 提交于 2019-12-01 17:03:39
I'm trying to sort a 10k element list in prolog with bubblesort and I get the out of local stack error. Mergesort seems to be the best option since I don't get any errors for the same input. However I'd really like to get some running times for bubblesort with large input data but I can't. Any ideas? Here's the code: %% NOTE: SWI-PROLOG USED %% generate_list(Limit, N, L): - insert upper limit and length of list N %% to get a random list with N numbers from 0 to limit generate_list(_, 0, []). generate_list(Limit, N, [Y|L]):- N =\= 0, random(0, Limit, Y), N1 is N-1, generate_list(Limit, N1, L).

Which goes on the stack or heap?

孤街醉人 提交于 2019-12-01 16:59:31
I am doing some studying and I came across a question that asks to show the correct memory diagram of the following code: int [] d1 = new int[5]; d1[0] = 3; Integer [] d2 = new Integer[5]; d2[0] = new Integer(3); ArrayList d3 = new ArrayList(); d3.add(3); Here is my attempt at a memory diagram, but it may be incorrect: I understand things like objects, instance variables, and "new" instances are all on the heap and things such as local variables and primitive types are on the stack, but I'm still confused when it comes to array types. Any help is appreciated. Any Object on Java lives on heap.

How to increase stack size in bison (and solve “memory exhausted”)

家住魔仙堡 提交于 2019-12-01 16:10:54
问题 My bison-based parser started choking on some moderately sized files I've generated recently. It throws an exception about "memory exhausted." The bison man page says that this is likely due to use of right-hand recursion. Without trying to rewrite the grammar (I am on a tight deadline), I would like to simply increase the stack to get the parser to parse this file. I tried to follow the bison man page and #define YYMAXDEPTH to some number larger than the default 10000, but that didn't work.

How to send 4000+ requests in exactly 1 second?

一曲冷凌霜 提交于 2019-12-01 15:44:27
I have an HTTP GET request . I need to send the request to the application server for more than 4000 times exactly in 1 second. I'm sending these requests using JMeter. I have taken ethereal traces every time for each test using a sniffer tool ( Wireshark ). I have tried to achieve this from one machine, multiple machines (parallel) and even distributed mode. Actually, JMeter results are not my concern here. The concern of this test is to see that 4000 requests are hitting the server in one second at the sniffer tool. I have found almost 2500 request in 1 sec in ethereal trace while using the

Write a program to sort a stack in ascending order

[亡魂溺海] 提交于 2019-12-01 15:31:24
Can someone help look at my code, please? Thank you so much for your help. The input stack is [5, 2, 1, 9, 0, 10], my codes gave output stack [0, 9, 1, 2, 5, 10], 9 is not in the right position. import java.util.*; public class CC3_6 { public static void main(String[] args) { int[] data = {5, 2, 1, 9, 0, 10}; Stack<Integer> myStack = new Stack<Integer>(); for (int i = 0; i < data.length; i++){ myStack.push(data[i]); } System.out.println(sortStack(myStack)); } public static Stack<Integer> sortStack(Stack<Integer> origin) { if (origin == null) return null; if (origin.size() < 2) return origin;

Sorting large lists in Prolog: Not enough memory

浪子不回头ぞ 提交于 2019-12-01 15:23:37
问题 I'm trying to sort a 10k element list in prolog with bubblesort and I get the out of local stack error. Mergesort seems to be the best option since I don't get any errors for the same input. However I'd really like to get some running times for bubblesort with large input data but I can't. Any ideas? Here's the code: %% NOTE: SWI-PROLOG USED %% generate_list(Limit, N, L): - insert upper limit and length of list N %% to get a random list with N numbers from 0 to limit generate_list(_, 0, []).