All Questions
Tagged with heap-memory dynamic-memory-allocation
144 questions
-2
votes
1
answer
123
views
Why is there a heap-after-use error here? I am trying to solve a Leetcode problem in C++. I don't see any dangling pointers or refs to freed memory
I am trying to solve LeetCode 2487: Remove Nodes From Linked List, and I’ve implemented a solution in C++ that first reverses the list, then removes nodes that have a greater value node to their left (...
0
votes
0
answers
102
views
Heap Memory Stair-Case rising in SwiftUI project
A simple keyboard extension app showing continuous heap memory allocation each time open the keyboard on screen.
For easier understanding see the image below...
Here is the KeyboardViewController:
...
0
votes
5
answers
167
views
Do the C compilers preallocate every variable that exists in a program? Or do they allocate while the program is running?
For example, when I define a variable, like int x = 20; in a function that can possibly be called in main, does the compiler already allocates stack memory for that variable? 'Cause, as I said, it's a ...
2
votes
4
answers
382
views
I do not understand what exactly is dynamic memory allocation
So apparently dynamic memory allocation allows memory to be allocated during runtime instead of compile time like static memory allocation. I also understand that using these functions in malloc.h we ...
0
votes
1
answer
56
views
C++ Primer 5th Ed - Stanley Lipmann: Question on shared_ptr.unique() used in conjunction with shared_ptr.reset()
First we have a shared_ptr defined as below:
shared_ptr<int> p(new int(42));
According to the text below:
The reset member is often used together with unique to
control changes to the object ...
2
votes
1
answer
156
views
Does redim use the heap or the stack memory in VBA?
I know this is quite strange to ask for a language that is far from a low-level language such as C and C++, but it caught my attention that for example if I do this:
Dim tempArray(0 To 2) As Integer
...
1
vote
1
answer
34
views
Is it possible to determine whether and address was obtained using sbrk or mmap?
I am developing a heap memory allocator based on Hoard for educational purposes. I know how to allocate memory using sbrk and mmap and have developed toy level allocators before.
I want to use mmap ...
1
vote
0
answers
39
views
How does one free memory in the heap in risc-v assembly? [duplicate]
I am currently studying risc-v assembly and started to research more about the heap. In the current problem I'm solving, I'm creating a linked list by allocating space on the heap with a syscall and ...
0
votes
1
answer
47
views
why can i not free ctypes memory in c?
i have a python file that trys to free memory from an array created using ctypes:
import ctypes
import os
# Load the DLL
script_dir = os.path.dirname(os.path.abspath(__file__))
dll_path = os.path....
-4
votes
1
answer
95
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 ...
0
votes
0
answers
68
views
How does free() deallocate a block of Memory when only given the Start Address? [duplicate]
I'm currently working on my own Implementation of an Array-like Datatype for learning purposes.
My Problem is understanding how the free() functions knows how much to deallocate since I only pass in ...
-1
votes
1
answer
165
views
Partially deallocating structs/classes in C++
Is there a way to partially deallocate structs/classes in C++? I was trying to build some sort of a new pointer in C++ that point to RefCount
template<typename T>
struct RefCount {
unsigned ...
1
vote
2
answers
191
views
Guaranteed alignment of adress allocated by new expression
I am compiling the code with gcc 11.4 with -m32 -std=c++20 on Linux
alignof(max_align_t) == 16
__STDCPP_DEFAULT_NEW_ALIGNMENT__ == 16
What is the guaranteed alignment that I should expect from new ...
1
vote
0
answers
92
views
Can't track heap memory usage in my C program at runtime
I took a look at similar question but it didn't serve my purpose. My actual programme crashed due to increasing memory in "RES" section from "top" command in ubuntu linux which is ...
0
votes
0
answers
18
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 ...