stack

OpenMP: poor performance of heap arrays (stack arrays work fine)

允我心安 提交于 2019-12-17 21:54:29
问题 I am a fairly experienced OpenMP user, but I have just run into a puzzling problem, and I am hopeful that someone here could help. The problem is that a simple hashing algorithm performs well for stack-allocated arrays, but poorly for arrays on the heap. Example below uses i%M (i modulus M) to count every M-th integer in respective array element. For simplicity, imagine N=1000000, M=10. If N%M==0, then the result should be that every element of bins[] is equal to N/M: #pragma omp for for (int

What are SP (stack) and LR in ARM?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-17 21:38:25
问题 I am reading definitions over and over again and I still not getting what are SP and LR in ARM? I understand PC (it shows next instruction's address), SP and LR probably are similar, but I just don't get what it is. Could you please help me? edit: if you could explain it with examples, it would be superb. edit: finally figured out what LR is for, still not getting what SP is for. 回答1: LR is link register used to hold the return address for a function call. SP is stack pointer. The stack is

how does an optimizing c++ compiler reuse stack slots of a function?

廉价感情. 提交于 2019-12-17 20:58:58
问题 How does an optimizing c++ compiler determine when a stack slot of a function(part of stack frame of a function) is no longer needed by that function, so it can reuse its memory? . By stack slot I mean a part of stack frame of a function, not necessarily a whole stack frame of a function and an example to clarify the matter is, suppose we have a function that has six integer variables defined in its scope, when it's time to use sixth variable in the function, fifth variable's become useless

How to write a buffer-overflow exploit in GCC,windows XP,x86?

自闭症网瘾萝莉.ら 提交于 2019-12-17 20:08:24
问题 void function(int a, int b, int c) { char buffer1[5]; char buffer2[10]; int *ret; ret = buffer1 + 12; (*ret) += 8;//why is it 8?? } void main() { int x; x = 0; function(1,2,3); x = 1; printf("%d\n",x); } The above demo is from here: http://insecure.org/stf/smashstack.html But it's not working here: D:\test>gcc -Wall -Wextra hw.cpp && a.exe hw.cpp: In function `void function(int, int, int)': hw.cpp:6: warning: unused variable 'buffer2' hw.cpp: At global scope: hw.cpp:4: warning: unused

Why doesn't C++ support dynamic arrays on the stack? [closed]

我们两清 提交于 2019-12-17 18:27:51
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 8 years ago . In C99 this was legal: void f(size_t sz) { char arr[sz]; // ... } However, this - dynamically sized stack arrays - has been dropped in

Why Must I Initialize All Fields in my C# struct with a Non-Default Constructor?

删除回忆录丶 提交于 2019-12-17 18:20:59
问题 I would like to try this code: public struct Direction { private int _azimuth; public int Azimuth { get { return _azimuth; } set { _azimuth = value; } } public Direction(int azimuth) { Azimuth = azimuth } } But it fails on compilation, I understand that struct need to init all its fields. but i am trying to understand what happens under the CLR\IL hoods. why it need all the fields before any other method\property\this etc. Thanks. 回答1: Value Types are created on the stack (unless nested

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

試著忘記壹切 提交于 2019-12-17 17:39:16
问题 Is there a standard way to see how much stack space your app has and what the highest watermark for stack usage is during a run? Also in the dreaded case of actual overflow what happens? Does it crash, trigger an exception or signal? Is there a standard or is it different on all systems and compilers? I'm looking specifically for Windows, Linux and Macintosh. 回答1: On Windows a stack overflow exception will be generated. The following windows code illustrates this: #include <stdio.h> #include

Why is there no “sub rsp” instruction in this function prologue and why are function parameters stored at negative rbp offsets?

狂风中的少年 提交于 2019-12-17 17:04:17
问题 That's what I understood by reading some memory segmentation documents: when a function is called, there are a few instructions (called function prologue) that save the frame pointer on the stack, copy the value of the stack pointer into the base pointer and save some memory for local variables. Here's a trivial code I am trying to debug using GDB: void test_function(int a, int b, int c, int d) { int flag; char buffer[10]; flag = 31337; buffer[0] = 'A'; } int main() { test_function(1, 2, 3, 4

How to check if a String is balanced?

主宰稳场 提交于 2019-12-17 16:36:17
问题 I want to test if an input String is balanced. It would be balanced if there is a matching opening and closing parenthesis, bracket or brace. example: {} balanced () balanced [] balanced If S is balanced so is (S) If S and T are balanced so is ST public static boolean isBalanced(String in) { Stack st = new Stack(); for(char chr : in.toCharArray()) { if(chr == '{') st.push(chr); } return false; } I'm having problems choosing what to do. Should I put every opening or closing parenthesis,

StackWalk64 on Windows - Get symbol name

爱⌒轻易说出口 提交于 2019-12-17 16:28:51
问题 Alright, second question on SO in one day. Looks like Windows programming makes me happy... : S I'm currently trying to get the function call stack on a Win32 executable. This morning, I've also asked a question about this: Win32 - Backtrace from C code Now, I'm pretty sure that the StackWalk64 function is the key for this. I've read some articles on how to use it, as well as the MS documentation. It actually displays frames on my test program, so it kinda work... The problem is that I'm not