stack

SystemStackError (stack level too deep)

廉价感情. 提交于 2019-12-03 15:30:48
I'm developing an android app, and I need to have a json response of the show view about a saved object. Trying that, I receive: "SystemStackError (stack level too deep)" app/controllers/segnalaziones_controller.rb:74:in `create' app/controllers/segnalaziones_controller.rb:58:in `create' Here is the "Segnalazione" controller include Gft class SegnalazionesController < ApplicationController load_and_authorize_resource respond_to :json # GET /segnalaziones # GET /segnalaziones.xml # before_filter :authorize def index @segnalaziones = Segnalazione.order(:dataspedizione) respond_to do |format|

Linked list vs dynamic array for implementing a stack using vector class

[亡魂溺海] 提交于 2019-12-03 14:49:34
I was reading up on the two different ways of implementing a stack: linked list and dynamic arrays. The main advantage of a linked list over a dynamic array was that the linked list did not have to be resized while a dynamic array had to be resized if too many elements were inserted hence wasting alot of time and memory. That got me wondering if this is true for C++ (as there is a vector class which automatically resizes whenever new elements are inserted)? It's difficult to compare the two, because the patterns of their memory usage are quite different. Vector resizing A vector resizes itself

Why should pop() take an argument?

蓝咒 提交于 2019-12-03 13:16:24
Quick background I'm a Java developer who's been playing around with C++ in my free/bored time. Preface In C++, you often see pop taking an argument by reference: void pop(Item& removed); I understand that it is nice to "fill in" the parameter with what you removed. That totally makes sense to me. This way, the person who asked to remove the top item can have a look at what was removed. However, if I were to do this in Java, I'd do something like this: Item pop() throws StackException; This way, after the pop we return either: NULL as a result, an Item, or an exception would be thrown. My C++

Does C# System.String Instances Really End Up on the Heap?

寵の児 提交于 2019-12-03 13:08:23
问题 Let's consider some very simple C# code: static void Main(string[] args) { int i = 5; string s = "ABC"; bool b = false; } Jeffrey Richter's " CLR via C# " (Chapter 14) states that " The String type is derived immediately from Object, making it a reference type, and therefore, String objects (its array of characters) always live in the heap, never on a thread's stack ". Also referring to strings, on an example in the book quite similar to the one above: " The newobj IL instruction constructs a

Retrieving the Min element in a stack in O(1) Time

烂漫一生 提交于 2019-12-03 13:03:46
问题 The reason I'm asking this question is because I cannot see why the way I think cannot be applied to this particular question "How would you design a stack which, in addition to push and pop, also has a function min which returns the minimum element? Push, pop and min should all operate in O(1) time " My basic solution: Wouldn't it be possible if we had a variable in stack class, that whenever we were pushing an item to stack we would check if it is smaller than our min variable. If it is

Pushing a Lua table

筅森魡賤 提交于 2019-12-03 12:57:36
I have created a Lua table in C , but I'm not sure how to push that table onto the top of a stack so I can pass it to a Lua function. Does anyone know how to do this? This is my current code: lua_createtable(state, libraries.size(), 0); int table_index = lua_gettop(state); for (int i = 0; i < libraries.size(); i++) { lua_pushstring(state, libraries[i].c_str()); lua_rawseti(state, table_index, i + 1); } lua_settable(state, -3); [ Push other things ] [ Call function ] Here's a quick helper function to push strings to the table void l_pushtablestring(lua_State* L , char* key , char* value) { lua

Why is my compiler reserving more space than required for a function stack frame?

本秂侑毒 提交于 2019-12-03 12:51:01
I have a function: void func(int a) { int x = a+2; } In the assembly code, in function prolog: push %ebp mov %esp, %ebp sub $0x10, %esp The code only needs to reserve space for x i.e. 4 bytes. But it is reserving 16 bytes. Why is that ? I have always seen it to reserve more space than required. My guess: it tends to store in 16 bytes. i.e. if I needed say 20 bytes, it will reserve 32 bytes, no matter what. This highly depends on your architecture and compiler flags, so it is impossible to point to a single thing and say "this must be it" here. However, I can give you some pointers you may find

comparison of access performance of data in heap and stack

爷,独闯天下 提交于 2019-12-03 12:32:45
问题 It is widely known common sense, that for most algorithms, allocating and deallocating data on the stack is much faster than doing so on the heap. In C++, the difference in the code is like double foo[n*n] vs. double* foo = new int[n*n] But there are any significant differences, when it comes to accessing and calculating with data that lie either on the heap or on the stack? I.e. is there a speed difference for foo[i] The code is ought to run on several different architectures, therefore try

Thread safety with heap-allocated memory

ぃ、小莉子 提交于 2019-12-03 12:00:42
问题 I was reading this: http://en.wikipedia.org/wiki/Thread_safety Is the following function thread-safe? void foo(int y){ int * x = new int[50]; /*...do some stuff with the allocated memory...*/ delete [] x; } In the article it says that to be thread-safe you can only use variables from the stack. Really? Why? Wouldn't subsequent calls of the above function allocate memory elsewhere? Edit: Ah. Looks like I misread this part of the article: A subroutine is reentrant, and thus thread-safe, if the

Get notified when a view controller is about to be popped in iOS4

不想你离开。 提交于 2019-12-03 11:53:36
This question has been asked before, but the answered ones I could find were from 2009 and don't suit my problem. Let me reiterate the issue. I have a UINavigationController that spawns and pushes lots of different UIViewController s onto its stack. One of those deals with some Core Data operations that need to be saved when that one particular VC get's popped off the stack. Don't focus on the Core Data part, it's about the popping. How can I hook into the moment that the UIViewController is going to be popped off the stack? I was hoping for a delegate method of some sort, but couldn't find it