Java Collections (LIFO Structure)

There’s actually a Stack class: http://java.sun.com/j2se/1.5.0/docs/api/java/util/Stack.html If you don’t want to use that, the LinkedList class (http://java.sun.com/j2se/1.5.0/docs/api/java/util/LinkedList.html) has addFirst and addLast and removeFirst and removeLast methods, making it perfect for use as a stack or queue class.

How to detect possible / potential stack overflow problems in a c / c++ program?

On Windows a stack overflow exception will be generated. The following windows code illustrates this: #include <stdio.h> #include <windows.h> void StackOverFlow() { CONTEXT context; // we are interested control registers context.ContextFlags = CONTEXT_CONTROL; // get the details GetThreadContext(GetCurrentThread(), &context); // print the stack pointer printf(“Esp: %X\n”, context.Esp); // this will eventually overflow the stack StackOverFlow(); … Read more

Removing range (tail) from a List

subList(list.size() – N, list.size()).clear() is the recommended way to remove the last N elements. Indeed, the Javadoc for subList specifically recommends this idiom: This method eliminates the need for explicit range operations (of the sort that commonly exist for arrays). Any operation that expects a list can be used as a range operation by passing … Read more

Checking available stack size in C

The getrusage function gets you the current usage . (see man getrusage). The getrlimit in Linux would help fetching the stack size with the RLIMIT_STACK parameter. #include <sys/resource.h> int main (void) { struct rlimit limit; getrlimit (RLIMIT_STACK, &limit); printf (“\nStack Limit = %ld and %ld max\n”, limit.rlim_cur, limit.rlim_max); } Please give a look at man … Read more

Setting stacksize in a python script

I have good experience with the following code. It doesn’t require any special user permissions: import resource, sys resource.setrlimit(resource.RLIMIT_STACK, (2**29,-1)) sys.setrecursionlimit(10**6) It does however not seem to work with pypy. If resource.setrlimit doesn’t work, you can also try using threads: sys.setrecursionlimit(10**6) import threading threading.stack_size(2**26) threading.Thread(target=main).start()

Stack-buffer based STL allocator?

It’s definitely possible to create a fully C++11/C++14 conforming stack allocator*. But you need to consider some of the ramifications about the implementation and the semantics of stack allocation and how they interact with standard containers. Here’s a fully C++11/C++14 conforming stack allocator (also hosted on my github): #include <functional> #include <memory> template <class T, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)