Skip to main content

All Questions

Filter by
Sorted by
Tagged with
-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 ...
Suthekshan 's user avatar
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 ...
Shivaraj CM's user avatar
1 vote
2 answers
98 views

local variables created by a data function by a dynamic object (heap) are stored in the heap or stack?

In C++, if I instantiate an object dynamically and it is stored in the heap, when this object calls one of its data functions which creates local variables, are these local variables stored in the ...
Santi J Fry's user avatar
0 votes
1 answer
562 views

A class with a pointer pointing to another class as a member variable and pushing it into vector

using namespace std; class B { public: B() :m_i(0), m_Name("") {}; B(const int num, const string& name) :m_i(num), m_Name(name) {}; void showInfo() { cout << ...
GreenBlue7's user avatar
1 vote
1 answer
149 views

C: Is my understanding about the specifics of heap and stack allocation correct?

I have a sort of linked list implemented (code at bottom) in C (which has obvious issues, but I'm not asking about those or about linked lists; I'm aware for instance that there are no calls to free() ...
HHHH's user avatar
  • 101
0 votes
1 answer
183 views

why is malloc still needed if VLAs exist? [duplicate]

As known, there are two types of arrays, static and dynamic. Static arrays size is defined at compile time, dynamic array size is defined using malloc. In this code you can see that I haven't use ...
Rohan jangid's user avatar
2 votes
0 answers
89 views

How to force dynamically allocated classes to have their members allocate on the heap as well? [duplicate]

Currently working on cross-platform allocation, where I am given a system, which has a very limited "stack" as an automatic scope for variables. However, said stack is still commonly used and filling ...
Nikita's user avatar
  • 649
0 votes
2 answers
2k views

Is memory to array allocated on stack or heap in java? [duplicate]

a code snippet Scanner sc=new Scanner(System.in); System.out.println("enter size of array"); int size=sc.nextInt(); int[] arr=new int[size];//Is the array arr allocated on heap? Is ...
skm's user avatar
  • 25
3 votes
3 answers
599 views

Why does my object appear to be on the heap without using `new`?

I'm starting to learn the topic of dynamic memory allocation. I have the following code: #include <iostream> #include "A.h" #include "B.h" using namespace std; int main() { /* Both ...
AndreStony's user avatar
0 votes
2 answers
2k views

Passing a stack allocated argument by reference to an array

I have a function say void theFunc(int num&, int* array) that takes in a an int by reference and an array pointer theFunc(int num&, int* array) { array[0] = num; } this is just an example, ...
tacobadger's user avatar
2 votes
3 answers
3k views

Are activation records created on stack or heap in C?

I am reading about memory allocation and activation records. I am having some doubts. Can anyone make the following crystal clear ? A). My first doubt is that "Are activation records created on stack ...
Garrick's user avatar
  • 689
1 vote
7 answers
742 views

Why is it impossible to allocate an array of an arbitrary size on the stack?

Why can't I write the following? char acBuf[nSize]; Only to prevent the stack from overgrowing? Or is there a possibility to do something similar, if I can ensure that I always take just a few ...
Allgaeuer's user avatar
  • 785
0 votes
3 answers
376 views

Variables stored on heap vs. stack in a non-fully compiled language (e.g. Java)?

I'm learning Java and reading how primitives (defined in methods) are stored on "the stack," vs. other things which are stored on "the heap." But, Java is not a fully compiled to executable language, ...
user3373520's user avatar
0 votes
1 answer
351 views

C++ Is it possible to leak memory if i'm not using dynamic memory

None of my code uses dynamic memory, but I do have a vector of pointers to a struct called Node, and in my code, I do lose references to those Nodes at one point. The struct looks like this: struct ...
jai's user avatar
  • 1
5 votes
2 answers
2k views

Are variables on the stack "statically allocated"?

I was reading this article and saw this: "This article assumes that you already know and understand at least basically how the memory map in GNU/Linux system works, and specially the difference ...
random_stuff's user avatar

15 30 50 per page