Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [heap]

The tag has no usage guidance.

1
vote
1answer
123 views

Are the Stack and Heap hardware, OS, or language-specific concepts?

In languages such as C or Java we have the concepts of the Stack and the Heap. Are these abstractions the particular language runtime/compiler creates over the plain-old RAM? Or are these concepts ...
1
vote
2answers
108 views

Is it a good idea to use strings in a struct as values to static properties?

I'm in a discussion with a co-worker concerning the use of structs. I have a couple of structs that contain several static properties that are used throughout our website. The value of those ...
0
votes
2answers
122 views

Should I always allocate QObject and derived classes to the heap?

I was in #Qt irc channel, and I showed a small snippet of my code in a style that I heavily rely upon. It looks like this: /* Get Reply from Server */ QPointer<QNetworkReply> reply; { ...
0
votes
1answer
118 views

Algorithm for graphing heap data from server memory, over long period of time

Right now I am collecting memory information on a node.js server every 100 seconds. I want do display the memory usage info as a graph on the front end. const mem = { heapTotals: [], heapUseds: []...
3
votes
1answer
404 views

C++ Are members of a class pointer automatically on heap?

Let's say we have a struct Vector2i { int x = 0, int y = 0 }; And create a Pointer to it via Vector2i* pointer = new Vector2i; Where would int x and int y be stored? Heap or stack? Are all members ...
3
votes
3answers
879 views

Is O(log n) for memory management considered slow?

I am talking about single thread general purpose memory allocation/deallocation from a global 'heap' as e.g. every C programmer knows in the form of malloc()/free(). I can't recite the actual title ...
1
vote
0answers
158 views

Caluclate needed heap size needed for serialization

In my current Java EE project I've got a quite common task: Load objects from database using Hibernate, transfer them in another object structure (based on a XSD) and serialize it using JAXB. To ...
2
votes
2answers
2k views

Does Java copy method parameters to the stack frame of the called method?

This is part of the answer about stack and heap in Java: So, why have the stack or the heap at all? For things that leave scope, the stack can be expensive. Consider the code: void foo(String ...
2
votes
3answers
2k views

Different types of heap in java

I was faced with this question recently for the different types of heap memory available in Java. I couldn't find much information online. Are there different types of heap memory available in Java ?...
3
votes
1answer
196 views

Segmentation and Object File Segments

I'm struggling to really understand memory segmentation. It's the topic of memory segmentation related to segments like heap,stack,code in an object file? Maybe they're for sure, but I still ...
2
votes
1answer
1k views

Find k max integers of an array — Min Heap vs. Selection Algo vs. Selection Sort

I have an array with a large number of elements, and I need to find the k largest elements. For an idea of scale, let us assume an integer array of length 10,000,000, and k is 1,000. I see three ...
7
votes
6answers
1k views

In C++; How big should an object [that will be transferred between functions] be before I consider delegating it to the heap?

In my day to day programming, I tend to use very few pointers, not only because I want to keep my code simple and error free, but because I assume that the programming that I do does not have any ...
1
vote
1answer
281 views

How is the Heap data structure useful?

Now that we have Red Black trees and AVL trees, it means that inserts and deletes take log(N) time. (We also note that find_min() would take log(N) time). Comparing these to heap, we have same ...
0
votes
1answer
944 views

Why doesn't a max-heap have a decrease-key operation, and a min-heap a increase-key operation?

The operation of increase-key or decrease-key is for updating a key within a max- or min-heap, respectively. Why doesn't a max-heap have a decrease-key operation, and a min-heap a increase-key ...
0
votes
1answer
7k views

how is stack and heap are assigned to each processes?

How multiples processes are stored in the main memory , i understand every process will be divided into the equal size pages and will be stored in the frames of main memory. if whole main memory is ...
-2
votes
1answer
1k views

stack based vs heap based overflow [closed]

Why is it more difficult to perform a heap based buffer overflow than a stack based? (regarding x86 architecture) I thought it could be the fact that heaps are allocating memory dynamically. But is ...
1
vote
1answer
247 views

Is stack allocation in Java implementation dependent?

I've looked through the different threads, and there are a lot of conflicting information out there. The most useful article I found was this: Java theory and practice: Urban performance legends, ...
6
votes
2answers
3k views

What is time complexity of update in binary heap?

For a binary heap we have O(log(n)) for insert, O(log(n)) for delete min and heap construction can be done in O(n). In the context of using a binary heap in Djikstra, my exam paper involved an "...
4
votes
2answers
469 views

MaxHeap-like data structure supporting max AND min, also decrease-key (yes decrease-key)

For the purpose of implementing an optimization algorithm (finding the minimum of a multivariate function) I want to create a data structure that supports the following operations: load from array ...
3
votes
2answers
302 views

Place variables frequently used by the same function on the heap?

Say that I have the following situation: void myFunc() { int x; //Do something with x } "x" is placed on the stack which is no doubt fast. Now, "myFunc" is called very frequently, lets say ...
3
votes
1answer
1k views

Does the JVM's Garbage Collector clean the entire JVM HotSpot memory (C-Heap, Java Heap and Permanent Generation space) or just Java Heap?

I know that the JVM has some JVM HotSpot memory which is further divided into three areas: Java Heap Permanent Generation Space Native Heap (C-Heap) I know that Java has automatic garbage collection ...
3
votes
1answer
506 views

How to make max-heap stable with counter and account for counter overflow?

Generally I need size-efficient data structure similar to std::priority_queue but stable (preserving order of insertion). By adding just 4 bytes to the object I could have 1 byte serving as priority ...
3
votes
3answers
2k views

instance methods, stack or heap

Do methods (and their variables) that belong to an object instance go on the stack or the heap? Ex Main() { Myclass Myobj = new Myclass(); Myobj.Doit(); } class Myclass { Void Doit() { Int myint ...
2
votes
1answer
316 views

Is the JVM “heap” inside the JVM software, or inside the physical computer?

I wanted to as this question about VMs in general, but focused it to JVM implementations only so this doesn't get closed as too broad. The JVM has a concept of a "heap". If my understanding is ...
5
votes
3answers
657 views

To find the oldest/newest element in a heap

I want to find the oldest/newest element added into a heap of size k. At any given point of time if I have to find say the oldest element in the heap is there any approach with O(1) space and O(1) ...
0
votes
1answer
175 views

Is my 'variable-storing area' basically a 'heap'?

I'm planning to implement a simple VM/interpreter kind of thing for a simple language I'm making. The compiler of the language emits mostly stack-oriented instructions to be executed by the VM. The ...
2
votes
4answers
916 views

Why is it called a memory leak?

I am a hobbyist programmer, bit of a stickler for terminology, currently learning C and recently came across the concept of Memory Leak. Now, I do understand what it means. Dynamic memory allocated to ...
1
vote
1answer
2k views

What happens when both heap and stack are full?

Suppose I am using a very heavy applications(or you can say that it is a very bad code which keeps on allocating memory on heap and won't free it and also uses recursion) Now after some point of time ...
13
votes
5answers
9k views

Java Heap Allocation Faster than C++

I already posted this question on SO and it did ok. It was unfortunately closed though(only needs one vote to reopen) but someone suggested I post it on here as it is a better fit so the following is ...
18
votes
2answers
32k views

How are the size of the stack and heap limited by the OS?

Note: if you need to consider a specific OS to be able to answer, please consider Linux. Whenever I run a program, it will be given a virtual memory space to run in, with an area for its stack and ...
3
votes
1answer
299 views

Is there a name for a randomized heap?

I've made a container which functions like a Binary Heap in terms of insertions and popping the root element. The key difference is that the comparison steps are all replaced with a random call for ...
4
votes
6answers
10k views

Heap overflow vs stack overflow

So as a general rule to avoid a stack overflow, big objects should be allocated to the heap (correct me if I am wrong). But, since the heap and the stack expand towards each other, wouldn't this cause ...
3
votes
4answers
10k views

Applications of heapsort [closed]

Heapsort is a sorting algorithm that has a time complexity of O(nlogn), and performs sorting using O(1) space complexity. However, I know that because it's unstable, it doesn't find many applications (...
9
votes
3answers
18k views

A good C Variable Length Array example [closed]

This question got rather a freezing reception at SO, so I decided to delete it there and try here instead. If you think it does not fit here either, please at least leave a comment on suggestion how ...
2
votes
1answer
1k views

Marked nodes in Fibonacci heaps

I don't understand why Fibonacci heaps have marked nodes (picture). A node is marked when its child is deleted. Quoting from Wikipedia: "[Keeping degree of each node low] is achieved by the rule that ...
10
votes
1answer
924 views

Why is the main memory for object allocation called the 'heap'?

Has anybody got an idea why the area of main memory where objects are allocated is referred to as the heap. I can understand the rationale for that of the stack LIFO but would like to know what the ...
4
votes
1answer
1k views

How does a priority_queue maintain a heap on a deque efficiently?

In the C++ STL, priority_queue (heap) can be used with any underlying container, such as a deque. How does the implementation stay O(log n) if deques don't swap an item in index a with index b in ...
1
vote
1answer
653 views

find second smallest element in Fibonacci Heap

I need to describe an algorithm that finds the second smallest element in a Fibonacci-Heap using the Operations: Insert, ExtractMin, DecreaseKey and GetMin. The last one is an algorithm previously ...
6
votes
4answers
4k views

Stack and heap - dynamic allocation question

Sources usually mention that dynamically created variables are allocated on the heap, while functions' variables on the stack. Also the ones on the stack cease to exist automatically when e.g. the ...
4
votes
5answers
1k views

Java heap space

In Java/JVM, why do we call the memory place where Java creates objects as "Heap"? Does it use the Heap Data Structure to create/remove/maintain the objects? As I read in the documentation of Heap ...
-4
votes
1answer
604 views

Construct an array from an existing array

Given an array of integers A[1...n-1] where 'N' is the length of array A[ ]. Construct an array B such that B[i] = min(A[i], A[i+1], ..., A[i+K-1]), where K will be given. Array B will have N-K+...
1
vote
1answer
239 views

Common diagnostics which VisualVM is used for

There's a lot of documentation out there on how to use the 'jvisualvm' profiler, but very little (if any) real-life advice on how to analyze all those charts and dumps. I'm just a little overwhelmed ...
9
votes
3answers
7k views

Custom heap allocators

Most programs can be quite casual about heap allocation, even to the extent that functional programming languages prefer to allocate new objects than modify old ones, and let the garbage collector ...
3
votes
1answer
4k views

At a higher level description, how is DLMALLOC supposed work?

There doesn't seem to be that many good descriptions that go into the specifics about how dlmalloc works. The sources I have come across so far mention dlmalloc, but then only goes on to explain what ...
3
votes
1answer
656 views

Are there some good algorithms for implementing a Heap that minimizes fragmentation?

Right now I'm trying to create a Heap that requires 8-byte alignment, and was looking around online for some good methods that would minimize the amount of fragmentation. Less fragmentation is ideal, ...
5
votes
2answers
370 views

Heaps: Why is there a tradeoff between amount of space occupied (fragmentation), and speed at which operations are carried out?

Apparently, the two major judging criteria of the effectiveness of heaps are (1) how much we can minimize the amount of space it takes up and (2) how fast operations on the heap can be carried out, eg,...
5
votes
2answers
1k views

Why in the world does a heap need to make sure it allocates in 8-byte alignments?

4-bytes = word; 8-bytes = 2x word Then why doesn't the heap just go with 4-byte alignment (because it will be grabbing a word at a time anyway, right?) If we went with 8-byte alignments, why not 12? ...
22
votes
6answers
12k views

Why do we need a Heap if everything can be done much more efficiently on the Stack?

This is actually somewhat related to the question I asked yesterday about why both a Stack and a Heap are necessary in the applications we use today (and why we can't just go with a Heap instead of ...
99
votes
6answers
149k views

Stack and Heap memory in Java

As I understand, in Java, stack memory holds primitives and method invocations and heap memory is used to store objects. Suppose I have a class class A { int a ; String b; //...