stack

SymGetLineFromAddr not working properly

廉价感情. 提交于 2019-12-09 01:08:39
问题 I have the following code: #include "stdafx.h" #include <process.h> #include <iostream> #include <Windows.h> #include "dbghelp.h" using namespace std; int LogStackTrace() { void *stack[1024]; HANDLE process = GetCurrentProcess(); SymInitialize(process, NULL, TRUE); WORD numberOfFrames = CaptureStackBackTrace(0, 1000, stack, NULL); SYMBOL_INFO *symbol = (SYMBOL_INFO *)malloc(sizeof(SYMBOL_INFO)); symbol->MaxNameLen = 1024; symbol->SizeOfStruct = sizeof(SYMBOL_INFO); IMAGEHLP_LINE *line =

Stack<T> implements ICollection, but has methods from ICollection<T>

南笙酒味 提交于 2019-12-08 19:44:19
问题 I'm trying to create a custom collection based on Stack<T> . When I look at Stack<T> [from metadata] in visual studio, it shows that Stack<T> implements ICollection , which would require it to implement ICollection 's CopyTo(Array array, index) method, but instead, it is shown as having ICollection<T> 's CopyTo(T[] array, index) method. Can someone explain why this is the case? I'm trying to create a collection that mimics Stack<T> pretty heavily. When I implement ICollection as stack does,

Warning message regarding stack size

霸气de小男生 提交于 2019-12-08 18:06:42
问题 I use Visual Studio 2010 with Code Analysis activated. In my code there's a line allocating some memory in a function: TCHAR someString[40000]; The code analysis throws a warning message: warning C6262: Function uses '40000' bytes of stack: exceeds /analyze:stacksize'16384'. Consider moving some data to heap I wonder if I should take the warning serious. Do I have to face some real trouble if I allocate some memory on the stack > 16384? Or is it just a general warning message which reminds me

Implementing Stack with Python

北城余情 提交于 2019-12-08 17:43:35
问题 I am trying to implement a simple stack with Python using arrays. I was wondering if someone could let me know what's wrong with my code. class myStack: def __init__(self): self = [] def isEmpty(self): return self == [] def push(self, item): self.append(item) def pop(self): return self.pop(0) def size(self): return len(self) s = myStack() s.push('1') s.push('2') print(s.pop()) print s 回答1: I corrected a few problems below. Also, a 'stack', in abstract programming terms, is usually a

Can I change the stack size limits from within the program?

℡╲_俬逩灬. 提交于 2019-12-08 16:54:03
问题 I can configure the maximum stack size of a GHC compiled Haskell program by passing +RTS -Kn to it, where n is some number. Is there a way to change this setting from within the program? (I’d like to benchmark stack consumption of various functions, and hence try to run it with various limits, catching the StackOverflow exception.) 回答1: Time has answered this with: „No“ 来源: https://stackoverflow.com/questions/19950074/can-i-change-the-stack-size-limits-from-within-the-program

Why is a function call, rather than variable addresses, used to detect stack growth direction?

醉酒当歌 提交于 2019-12-08 16:43:54
问题 I read different responses to the question of detecting stack growth detection and I understand that, in modern architectures, stack might grow randomly, might be created off heap, and so on. However, in this classic interview question, I want to understand why people use a function call rather than comparing 2 local variables in the same function. I think there must be some particular reason for doing this but, not being a C/low level developer [Java :)], I am simply guessing. Here is the

Add to stack from ArrayList (Java)

假装没事ソ 提交于 2019-12-08 16:33:28
问题 I have an ArrayList pre-defined with hardcoded values. How do I add these to a stack? The idea is to demonstrate the pop, push, peek functions of the stack class. ArrayList<String> al = new ArrayList<String>(); al.add("A"); al.add("B"); al.add("C"); Stack<String> st = new Stack<String>(); st.push(al); **// This doesn't seem to work.. Will I have to loop it in some way?** System.out.println(st); Thanks! 回答1: Like many collection classes, Stack provides a addAll method : st.addAll(al) 回答2: Why

Why is it allowed to declare an automatic array with size depending on user input? [duplicate]

假如想象 提交于 2019-12-08 15:55:21
问题 This question already has answers here : Why aren't variable-length arrays part of the C++ standard? (12 answers) Closed last year . I'm using MinGW to compile for C++11 and I found out that this doesn't throw an error: int S; cin>>S; char array[S]; While this does ("storage size of 'array' isn't known"): char array[]; To me, the size is also unknown in the first case, as it depends on what the user input is. As far as I knew, automatic arrays are allocated at compile time in stack memory. So

stack.ToList() – order of elements?

非 Y 不嫁゛ 提交于 2019-12-08 14:46:35
问题 When using the .ToList() extension method on a Stack<T> , is the result the same as popping each element and adding to a new list (reverse of what was pushed)? If so, is this because it really is iterating over each element, or does it store the elements in reverse internally and slip the array into a new List<T> ? 回答1: Stack itself does not have a ToList method, it's the extension method from the Enumerable class. As those extension methods only deal with IEnumerable<T> , it's safe to assume

How to NULL a pointer (to a struct) from within a function

♀尐吖头ヾ 提交于 2019-12-08 14:08:49
问题 One Liner Question: Can someone please explain why thisNode=NULL doesn't work in a function and how I can achieve the same result in some other way. Introduction: I have started using pointers to structs a lot recently as I have started studying Data Structures. History: I have coded stacks, queues, binary search trees and expression trees and will start coding an avl tree soon. Being a student I still am unaware of many concepts and would appreciate any help. Methodology: I always find other