Skip to main content

Questions tagged [stack-memory]

Questions regarding process stack memory. Generally, stack memory is sequentially allocated, scoped to successive function calls, and normally referenced by the CPU using a stack pointer register.

stack-memory
Filter by
Sorted by
Tagged with
-6 votes
0 answers
76 views

Static variables in C++ [duplicate]

Where are static variables allocated in C++? On the stack or the heap? Also, I read in 7.9 — The stack and the heap that all memory allocated on the stack is known at compile time. Is it true? Does it ...
Ibrahim Al-Etrebi's user avatar
-2 votes
0 answers
51 views

c++ heap vs stack allocation for append function call [duplicate]

If I have a string in C++: std:string a = std:string("haha"); Does it get allocated on the stack since it's a local variable? Or since it's the std::string type, does it directly go on the ...
hooistheman's user avatar
0 votes
1 answer
67 views

How does array padding works in Stack?

The following question refers to x86 assembly, and little endianness. Suppose I have the following code in C: unsigned char myID[10] = "211866744"; How will this array be saved in memory? ...
David's user avatar
  • 53
-3 votes
2 answers
63 views

Define/Initialize Vectors on Stack vs Heap [closed]

I declare two vectors in my class header file as follows: struct MYDATA { uint8_t A = 0; uint8_t B = 0; }; std::vector<MYDATA> vector1; std::vector<MYDATA> *vector2 = new std::...
Torisoft's user avatar
-3 votes
1 answer
76 views

How is Numpy able to get an array size at run-time?

In C++ the size of an array must be determined at the compile-time. I want to write a simple code in C++, say, to do a naive matrix multiplication with itself (for a matrix that is square in size) and ...
MOON's user avatar
  • 2,732
2 votes
2 answers
91 views

If the stack grows downwards, how does it not overlap with other stuff in the address space?

I realized I never really thought of this. If I made a large enough recursive call chain, wouldn't the stack eventually grow down enough that it will overlap with other things, like shared libraries (...
natitati's user avatar
  • 167
0 votes
1 answer
60 views

Stack size in relation to virtual memory

In our Operating Systems class we mentioned virtual memory as a mechanism that abstracts physical memory to a process, and that it looks something like this (per process): The stack grows down the ...
lukascobbler's user avatar
5 votes
1 answer
88 views

Why does the Stack Pointer in MIPS Typically Start at 0x7FFFFFFC but not 0x80000000?

According to Patterson & Hennessy's Computer Organization and Design (MIPS Edition), the stack pointer $sp is typically initialized to 0x7FFFFFFC. the stack pointer $sp is always pointing at the ...
Flandia Yingman's user avatar
0 votes
2 answers
101 views

Does Stack being limited in size mean i can only get limited pointers to objects in heap?

if stack size is 1MB, does that mean i can only get less than 1000000/8 pointers to allocate ints in heap? (considering 1MB free stack) yeah i know you might not want to make that many individual ints ...
Nemexia's user avatar
  • 139
-3 votes
2 answers
120 views

Why is there no time cost to large stack allocations

I tried this quick-bench test and I'm finding that it's the same cost timewise to allocate 200 bytes as it is to allocate 2000000 bytes. How could that possibly be?
bobobobo's user avatar
  • 66.6k
0 votes
0 answers
12 views

How to assign the stack/heap area into the external ram

How could I assign the stack/heap area into the external RAM on the KEIL SDK. My scatter file is like the following. LR_IROM1 0x01008000 0x00400000 { ; load region size_region ER_IROM1 ...
andy's user avatar
  • 117
0 votes
0 answers
38 views

With what part of the program are the stack and heap associated?

I understanding the stack, the LIFO working principle, memory allocation on the heap and stuff. My question is, where does this exists ? Is there a dedicated region on the ram for the stack ? Or is it ...
Out Bruh's user avatar
0 votes
3 answers
106 views

Get stack trace from ELF and stack hex

I'm working on a core dump mechanism for STM32 mcus running FreeRTOS. I managed to extract the stack of the running tasks, and transmit it to a server where a python script writes it into a hex file. ...
KubbyDev's user avatar
-3 votes
1 answer
82 views

pointers from heap and instances from stack C++ [closed]

My purpose is to determine if I should deallocate using delete a variable to a pointer stored in a linked list... I had the idea to consider that any pointer allocated in the heap will be strictly ...
David Harouche's user avatar
0 votes
0 answers
54 views

"Symbol not defined : @STACK " error in ASM code for 8086. Compiled using DOSBOX ,MASM

This is a code to add all numbers between 50 and 150 and display the result in decimal form.I have created the stack segment .STACK 32 to store the remainders to convert the hex result to decimal ...
Bishal Lamichhane's user avatar
-4 votes
1 answer
91 views

C-Dynamic Memory Allocation

typedef struct { double x; double y; } point; point p1; point* p2 = malloc(sizeof(point)); In this code where the variables p1,p2,p1.x, and p2->x are stored in stack or heap memory? Where ...
Suthekshan 's user avatar
0 votes
0 answers
43 views

Why doesn't pushing a character to the stack without an explicit nul-char look like an underfined behaviour? [duplicate]

The following snippet comes from the lesson 7 on asmtutor.com : ;------------------------------------------ ; void sprintLF(String message) ; String printing with line feed function sprintLF: call ...
vmonteco's user avatar
  • 15k
0 votes
1 answer
70 views

Buffer Overflow: Why does buffer assignment impact other variables?

void foo() { int value = 0; char buf[4]; buf[4] = 1; printf("value: %d\n", value); } int main() { foo(); return 0; } Why does 'value' print 1? I believe this has ...
miya's user avatar
  • 3
1 vote
1 answer
161 views

Aarch64 is there a Red Zone on Linux, If so 16 or 128 bytes?

There doesn't seem to be any mention of a "Red Zone" for Aarch64 in the ABI, but Microsoft makes reference to a 16-byte red zone for Aarch64, Apple claims a 128-byte red zone in Writing ...
David C. Rankin's user avatar
0 votes
0 answers
29 views

Issue with Assembly Code: Program Crashes at movb store to stack memory (%esp) [duplicate]

I am currently learning assembly and I am trying to write a simple program. I have the following code: .global do_main .section .text do_main: sub $4, %esp movb $'H', (%esp) movb $'e', 1(%...
Alfa Hores's user avatar
-3 votes
1 answer
94 views

Placing value on stack using alloca function or static keyword

I have an abstract "x vs y" question. In C programming language if I have some small amount of data which I want to store somewhere in RAM, I suppose typical options are the next ones: to ...
Eimrine's user avatar
  • 61
0 votes
1 answer
120 views

How objects are created and initialized in detail

I don't understand the logic of why the code results in stackOverFlow error: public class Human { private String name; private int age = 30; private Human human = new Human(); ...
NinaJava's user avatar
0 votes
0 answers
43 views

Use of Stack/Heap outside of programming

If I understand correctly, the RAM is virtually divided into stack and heap. Stack takes primitive types/functions etc and Heap deals with the reference types and objects. Stack follows the LIFO ...
Hopen's user avatar
  • 1
1 vote
1 answer
90 views

How to do pattern matching with boxed enum? [duplicate]

i have an enum where i have to perform pattern matching. But since i am running the program on VM which has limited stack memory ( < 4Kb ), i allocated the enum on the heap using Box. But while ...
Dhruv D Jain's user avatar
0 votes
0 answers
121 views

How to allocate a separate stack for a function manually in C++?

I am trying to allocate a new stack on the heap in C++ for a function using VirtualAlloc. While debugging, I noticed that the rsp value for my function can either increase or decrease relative to the ...
kliri's user avatar
  • 1
0 votes
0 answers
24 views

How do I get more stack space for g++

I'm trying to allocate 3 fairly large matrices using g++ on a MacBook pro 2019 model running Monterrey 12.7.1 with 8GB "main" memory. The purpose of this code to compare C++ to Octave. Here'...
Vitit Kantabutra's user avatar
0 votes
0 answers
61 views

I can't use RSP to reference the end of the stack

in my system (x86_64), when I'm using GDB, both RBP and RSP point to the same memory address after pushing a new stack frame, therefore I can't reference the end of the stack with the register RSP ...
strjak's user avatar
  • 5
1 vote
0 answers
390 views

Uncaught RangeError: Maximum call stack size exceeded (functionjs.js)

I'm trying to build a recruitment management website (nodejs), but when I'm almost done I get this error: Uncaught RangeError: Maximum call stack size exceeded. functionjs.js Here is my functionjs.js ...
Cmint's user avatar
  • 19
2 votes
2 answers
126 views

How to pass big data from a factory to a constructor with neither dynamic memory nor unnecessary copies?

Runge-Kutta schemes consist of an algorithm, implemented in Scheme, and a piece of data, called Table (Butcher tableau). For the construction of a scheme, we want consumers to use the syntax Scheme s =...
GRamon's user avatar
  • 77
1 vote
0 answers
34 views

How to get address range of a process stack in MacOS?

I'm debugging a program that has many alloca and triggers EXC_BAD_ACCESS (with -msanitize=address) or crashes __chkstk_darwin (without compiler sanitizer). I want to know the valid stack address range ...
jiandingzhe's user avatar
  • 2,017
0 votes
3 answers
97 views

How does my OS know if a defined variable is initialized or not?

At the moment I am messing around a little bit with Sorting Algorithms in C. In the course of this I have run into the following problem: I have defined an int array with int array[LENGTH]; where ...
LeChummpy's user avatar
3 votes
2 answers
113 views

How can I declare an array of pointers with blocks of NULL elems

I'm using an array of functions pointers, and I'd like to use it directly with their associated event IDs. Problem is, event IDs start from 0x10 to 0x1C, and from 0x90 to 0xA5. I don't want to write ...
mescande's user avatar
1 vote
2 answers
209 views

STM32F0 - question about memory (Stack, heap)

I am bit confused about the stack and heap memory of STM32 microcontrolers (cortex M0). Firstly, they are part of RAM, but are they part of RAM size described in the datasheet ? Secondly, if I reduce ...
NinjaGreg's user avatar
0 votes
1 answer
120 views

Why are some smaller embedded devices unable to run an operating system (and what exactly do they run off of instead)?

For context, this was taken from an excerpt in a book: Finally, sometimes you can't even use heap memory! If you are programming in Rust for a small embedded device, you are going to have to use only ...
Dainank's user avatar
  • 2,447
0 votes
1 answer
129 views

Is there a way to calculate the bytes allocated to the stack frame of a function?

I have been given this code in C and I need to calculate the bytes allocated to the stack frame of function arith. I looked everywhere for a way to do it but everyone has a different answer. long ...
Zayed Aldhaheri's user avatar
0 votes
0 answers
84 views

Problem with displaying stack values in a loop

rephrased the question Getting segmentation fault right after last printf after iterating and displaying stack values (2 iterations for simplicity purposes). Just trying to display hex value on the ...
T-series's user avatar
0 votes
1 answer
262 views

Memory Organization: Where Are Classes and Methods Stored?

I'm looking to understand the organization of memory in my programming language, which consists of four primary areas: stack, heap, code, and data. However, I'm unclear about where the programming ...
Hassan Lakhal's user avatar
1 vote
2 answers
163 views

How to recognize if object is on the stack or heap memory

I have recently received a university assignment for my Data Structures course, which requires me to create a doubly linked list in C++. While working on my doubly linked list, I needed to implement ...
Default's user avatar
  • 85
1 vote
1 answer
317 views

how the local variable are stored and returned in memory (python)?

I always used python without thinking its memory management. But, I have a big question about how it deals memory. def func1(): local_var = 1 print(id(local_var)) # memory address of ...
live-today's user avatar
4 votes
1 answer
408 views

Does the red zone still exist even if we use the -mno-red-zone flag in gcc?

My system: Ubuntu 22.04.3 running on x86_64. GCC version 11.4.0 I've read that the System V ABI mandates the red zone. From the GCC manual: The red zone is mandated by the x86-64 ABI, it is a 128-...
alessio solari's user avatar
1 vote
1 answer
99 views

Does the System V ABI on Ubuntu place the return address within the caller function's frame or the callee function's frame?

My system : Ubuntu 22.04.3 running on x86_64. GCC version 11.4.0 I'm asking this because it seems like there are two different representations of the return address as far as the frame it is within ( ...
alessio solari's user avatar
0 votes
1 answer
78 views

Get parameter value in Assembly

I'm a beginner in Assembly, so I'm confused about passing parameters in function call from another function. Specifically I have code like this: Assembly: bar: pushl %ebp movl %esp, %ebp subl $...
Võ Khắc Bảo's user avatar
1 vote
1 answer
95 views

Why is it that the rsp register is not decremented in a leaf function as it is at the beginning of any other functions? [duplicate]

Here's some information about my system: Ubuntu 22.04.3 running on Intel x86_64; ggc version 11.4.0; I've noticed that the rsp register is not decremented in leaf functions as it is in non leaf ...
alessio solari's user avatar
0 votes
1 answer
136 views

If Heap is dynamic then why it is placed in between stack and data area

I am currently learning about Operating systems and got struck at this. If the size of Heap area is dynamic then why it is placed at the bottom of the stack. If size of the heap increase will the ...
Tarun Mendu's user avatar
4 votes
1 answer
153 views

Why does Go use less memory for a slice of length 100k, than for an array of length 100k?

Consider the following code where I allocate 4 thousand arrays, each of length 100k: parentMap := make(map[int][100_000]int) for i := 0; i < 4000; i++ { parentMap[i] = [100_000]int{}...
Dan's user avatar
  • 711
0 votes
0 answers
15 views

Memory Allocation of Instance Variables

When we tell objects are created in heap memory and referenced in stack memory. The reference to the Objects are in stack but where do the Instance variables lie. Does each object have a collection on ...
Shivaraj CM's user avatar
2 votes
0 answers
31 views

x64 assembly code: Can I expect a value not allocated in the stack to remain without alteration? [duplicate]

Suppose that I have these two consecutive x64 instructions (running under Windows platform): ADD RSP, 8 MOV RAX, QWORD PTR [RSP - 8] As you see it's the equivalent to POP RAX. The location of [RSP - ...
raff's user avatar
  • 359
2 votes
1 answer
610 views

Error: C stack usage is too close to the limit, doing simple operation without recursion

I am running a script with fairly simple series of operations, converting some dates to Unix time, then adding these together. There is no recursion here, but I am getting a Error: C stack usage is ...
DinoDave's user avatar
0 votes
1 answer
64 views

Stack Initialization Problem in Real Mode: How to Properly Initialize the stack?

I am writing a simple boot loader in x86 assembly, here is the code for it : org 0x7C00 section boot start=0x7C00 ; initializing the stack mov ax,0xF000 mov ss,ax mov sp,0xFFFF mov bp,0xFFFF ; ...
Djebbar Abderrahmene's user avatar
0 votes
0 answers
22 views

Why does this stack array result in getline creating a segfault? [duplicate]

This code works if you remove the array, but I don't know why, and it always segfaults before the printing during the getline function. Why does it do this, and how do I fix it? My actual code looks a ...
Ethan's user avatar
  • 167

1
2 3 4 5
21