17

I believe I have a good understanding of what is stored on the stack(for example primitive data types) and what's stored on the heap(for example an instance of a class. But is there anyway to verify this for educational/verification of my expectations reasons?

It can be in a debugger(gdb or rad debugger or worst case vs) or directly code based(thinking something like gettype(variable) but like isstackstored(variable).

you are viewing a single comment's thread
view the rest of the comments
[-] vrek@programming.dev 3 points 3 days ago

Most of those will give me a memory address but is there a way to know if that address is stack or heap?

[-] tatterdemalion@programming.dev 3 points 3 days ago

info proc mappings should show you the memory regions mapped for stack and heap, then you can compare the address of your variable to those.

[-] vrek@programming.dev 2 points 3 days ago

I don't see that in the sourceware or gnu documentation but I may be missing it (gdb is incredibly complex and documentation in long and detailed). It's 1am here so investigation into this will have to wait till tomorrow.

this post was submitted on 01 Sep 2026
17 points (100.0% liked)

Learn Programming

2231 readers
53 users here now

Posting Etiquette

  1. Ask the main part of your question in the title. This should be concise but informative.

  2. Provide everything up front. Don't make people fish for more details in the comments. Provide background information and examples.

  3. Be present for follow up questions. Don't ask for help and run away. Stick around to answer questions and provide more details.

  4. Ask about the problem you're trying to solve. Don't focus too much on debugging your exact solution, as you may be going down the wrong path. Include as much information as you can about what you ultimately are trying to achieve. See more on this here: https://xyproblem.info/

Icon base by Delapouite under CC BY 3.0 with modifications to add a gradient

founded 3 years ago
MODERATORS