stack

Is using alloca() for variable length arrays better than using a vector on the heap?

纵饮孤独 提交于 2019-12-10 10:35:46
问题 I have some code using a variable length array (VLA), which compiles fine in gcc and clang, but does not work with MSVC 2015. class Test { public: Test() { P = 5; } void somemethod() { int array[P]; // do something with the array } private: int P; } There seem to be two solutions in the code: using alloca(), taking the risks of alloca in account by making absolutely sure not to access elements outside of the array. using a vector member variable (assuming that the overhead between vector and

Bring rasters to same extent by filling with NA - in R

╄→尐↘猪︶ㄣ 提交于 2019-12-10 10:28:28
问题 I have several cropped rasters with different geometry/outlines. Specifically spatial yield maps from several years of the same field, but the extent varies - the measurements were not always overall the whole field, but in some years only part of it. I want to calculate a mean value of those maps and combine them into one mean-value-raster. That does mean however, that not for every pixel in let's say 5 layers/rasters there is a value. I could accept these missing values to be NA, so the

Stack in Java, problem with “contains”

不羁的心 提交于 2019-12-10 10:27:03
问题 I'm using stack in my program but I have a problem when program is trying to check what element contains in stack. I'm using array of integer in Stack. Short example is: Stack<int[]> myStack = new Stack<int[]>(); myStack.push(new int[]{1,2}); myStack.push(new int[]{1,3}); myStack.push(new int[]{1,4}); if (myStack.contains(new int[]{1,3})) { System.out.println("YES"); } else { System.out.println("NO"); } Now it was printed "NO". How could I do to get "YES" ? I know that the problem is that I'm

Allocating a new call stack

百般思念 提交于 2019-12-10 04:12:27
问题 (I think there's a high chance of this question either being a duplicate or otherwise answered here already, but searching for the answer is hard thanks to interference from "stack allocation" and related terms.) I have a toy compiler I've been working on for a scripting language. In order to be able to pause the execution of a script while it's in progress and return to the host program, it has its own stack: a simple block of memory with a "stack pointer" variable that gets incremented

Is there a maximum limit to the size of a variable that should be allocated on a stack?

本秂侑毒 提交于 2019-12-10 02:38:45
问题 i declared a struct variable in C of size greater than 1024bytes. On running Coverity (a static code analyzer application) it reports that this stack variable is greater than 1024 bytes and therefore a cause of error. I'd like to know if I need to worry about this warning? Is there really a maximum limit to the size of a single stack variable? thanks, che 回答1: The maximum size of a variable is the limited by the maximum size of the stack (specifically, how much of the stack is left over from

Returning a pointer on stack

孤街醉人 提交于 2019-12-10 02:35:03
问题 In C when I return a pointer of a stack-created variable from a function, the memory discards after the function is returned, thus making the pointer impossible to dereference. But in Go, the compiler is not giving me any errors. Does that mean that this is safe to do? package main import ( "fmt" ) func main() { fmt.Println(*(something())) } func something() *string { s := "a" return &s } 回答1: Yes, this is safe and a normal pattern in Go programming. Go uses escape analysis to move any values

Convert from an infix expression to postfix (C++) using Stacks

旧巷老猫 提交于 2019-12-10 02:25:25
问题 My lecturer gave me an assignment to create a program to convert and infix expression to postfix using Stacks. I've made the stack classes and some functions to read the infix expression. But this one function, called convertToPostfix(char * const inFix, char * const postFix) which is responsible to convert the inFix expression in the array inFix to the post fix expression in the array postFix using stacks, is not doing what it suppose to do. Can you guys help me out and tell me what I'm

Stack and Stack Base Address

血红的双手。 提交于 2019-12-09 23:18:01
问题 In the MEMORY_BASIC_INFORMATION structure one finds two PVOID variables, called BaseAddress and AllocationBase respectively. I'm reading a book on Threading and its going over how to get the stackspace left on the stack in quite some detail, however there's something I'm not sure I understand correctly. The BaseAddress in the structure mentioned above, does it point to the highest address in the current thread stack or the lowest address? Since the stack grows downwards, the lowest would be

When does malloc return NULL in a bare-metal environment?

蓝咒 提交于 2019-12-09 18:40:59
问题 There is a c memory model as following : +--------+ Last Address of RAM | Stack | | | | | v | +--------+ RAM | | | | +--------+ | ^ | | | | | Heap | +--------+ | ZI | +--------+ | RW | +========+ First Address of RAM The stack and heap space increase in opposite directions. They would be overlapped with each other in the middle. So my questions are: In a bare-metal environment, when does malloc return NULL? In a bare-metal environment, how to prevent stack from overlapping with heap? 回答1:

Call to _freea really necessary?

本秂侑毒 提交于 2019-12-09 16:13:41
问题 I am developping on Windows with DevStudio, in C/C++ unmanaged. I want to allocate some memory on the stack instead of the heap because I don't want to have to deal with releasing that memory manually (I know about smart pointers and all those things. I have a very specific case of memory allocation I need to deal with), similar to the use of A2W() and W2A() macros. _alloca does that, but it is deprecated. It is suggested to use malloca instead. But _malloca documentation says that a call to