stack

Access local stack of linux threads (pthreads)

为君一笑 提交于 2019-12-10 15:42:46
问题 I'm currently implementing an application that makes use of multithreading but has requirements on the total memory consumption. I'd like to have a master thread doing I/O and several workers doing computations. Currently I'm having several datastructures on the masters stack that are accessed by the workers. I use OpenMP for work distribution. As the master/worker pattern doesn't work well with OpenMP I'd like to use pthreads for multithreading. I know that each thread maintains a local

pass by reference in assembly

非 Y 不嫁゛ 提交于 2019-12-10 15:28:50
问题 I am trying to write a program to calculate the exponential of a number using ARM-C inter-working. I am using LPC1769(cortex m3) for debuuging. The following is the code: /*here is the main.c file*/ #include<stdio.h> #include<stdlib.h> extern int Start (void); extern int Exponentiatecore(int *m,int *n); void print(int i); int Exponentiate(int *m,int *n); int main() { Start(); return 0; } int Exponentiate(int *m,int *n) { if (*n==0) return 1; else { int result; result=Exponentiatecore(m,n);

Function Pointer Memory Explanation in C

早过忘川 提交于 2019-12-10 14:28:28
问题 #include <stdio.h> #include <stdlib.h> int (*fptr1)(int); int square(int num){ return num*num; } void main(){ fptr1 = &square; printf("%d\n",fptr1(5)); } Can someone briefly explain what happens in stack when we call a function pointer? What is the difference between calling a function directly in main() and calling it by function pointer in C language by the means of physical memory and process? I tried to understand what happens in memory when we call a function with function pointer but it

Sorting an array with Stacks and Queues

↘锁芯ラ 提交于 2019-12-10 13:54:03
问题 I need to create a method which sorts an array of integers using a Stack and a Queue. For instance if given [-1, 7, 0, 3, -2] -> [-2, -1, 0, 3, 7]. I'm completely lost at how to do this question, because I would just use a sorting method, however for this question I am not allowed to do that. Can anyone explain how to do this with a Stack and a Queue? 回答1: Many fast sorting algorithms (for example mergesort and quicksort) can be implemented efficiently on linked lists by using the fact that

C++: Storing structs in a stack

寵の児 提交于 2019-12-10 13:24:45
问题 I have a struct: struct Vehicle { char ad; // Arrival departure char string license; // license value int arrival; // arrival in military time }; I want to store all the values in the struct in a stack. I can store one value in the stack by doing: stack<string> stack; // STL Stack object Vehicle v; //vehicle struct object stack.push(v.license); How can I store a the whole struct in the stack so I can later access the char, int, and, string? 回答1: Simple, just replace string for Vehicle and an

Replace the legacy Stack with what from Java Collections?

感情迁移 提交于 2019-12-10 12:54:54
问题 This is kind of a Java trivia question perhaps. I have used the Stack implementation many times. I have read that this is considered a legacy class and due to the fact that it subclasses Vector makes its performance bad in single threaded applications. My question is, what is the best alternative among the Java Collection classes? Is there another Stack class available (by a different name perhaps) that is the one to choose? I mean, ok implementing a stack arround another existing data

Javascript closures on heap or stack?

夙愿已清 提交于 2019-12-10 12:43:57
问题 Where does JavaScript (according to the standard) store closures: heap or stack? Is there a third explicit place for closures? 回答1: In the end it is an implementation detail of the runtime. See Phoenix link As to implementations, for storing local variables after the context is destroyed, the stack-based implementation is not fit any more (because it contradicts the definition of stack-based structure). Therefore in this case closured data of the parent context are saved in the dynamic memory

clearing stack of activities with just one press

夙愿已清 提交于 2019-12-10 12:20:07
问题 I have a launching Activity A1 which has a start button which starts a Service S1: startButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Log.i(TAG1, "Starting Update Service"); startService(serviceIntentS1); } }); S1 depending on some condition starts Activity A2: if (giveninteger>=2) { Intent intentA2= new Intent(this, A2.class); // following line to avoid exception intentA2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); //to avoid exception startActivity

gdb stack strangeness

北慕城南 提交于 2019-12-10 11:27:29
问题 I get this weird backtrace (sometimes): (gdb) bt #0 0x00002b36465a5d4c in AY16_Loop_M16 () from /opt/intel/mkl/10.0.3.020/lib/em64t/libmkl_mc.so #1 0x00000000000021da in ?? () #2 0x00000000000021da in ?? () #3 0xbf3e9dec2f04aeff in ?? () #4 0xbf480541bd29306a in ?? () #5 0xbf3e6017955273e8 in ?? () #6 0xbf442b937c2c1f37 in ?? () #7 0x3f5580165832d744 in ?? () ... Any ideas why i cant see the symbols? Compiled with debugging syms of course. The same session gives symbols at other points. 回答1:

NSLog(…) improper format specifier affects other variables?

一世执手 提交于 2019-12-10 11:25:25
问题 I recently wasted about half an hour tracking down this odd behavior in NSLog(...): NSString *text = @"abc"; long long num = 123; NSLog(@"num=%lld, text=%@",num,text); //(A) NSLog(@"num=%d, text=%@",num,text); //(B) Line (A) prints the expected "num=123, text=abc", but line (B) prints "num=123, text= (null) ". Obviously, printing a long long with %d is a mistake, but can someone explain why it would cause text to be printed as null? 回答1: You just messed up memory alignment on your stack. I