Questions tagged [heap]

A heap (data structure) is a tree that is ordered with respect to depth. Heap can also refer to process memory set aside for dynamic allocation.

In computer science, a heap is a specialized tree-based data structure that satisfies the heap property: If A is a parent node of B then key(A) is ordered with respect to key(B) with the same ordering applying across the heap. Either the keys of parent nodes are always greater than or equal to those of the children and the highest key is in the root node (this kind of heap is called max heap) or the keys of parent nodes are less than or equal to those of the children (min heap).

A heap memory pool is an internal memory pool created at start-up that tasks use to dynamically allocate memory as needed. This memory pool is used by tasks that requires a lot of memory from the stack, such as tasks that use wide columns.

For example, in Sybase's Adaptive Server Enterprise, if you make a wide column or row change, the temporary buffer this task uses can be as large as 16K, which is too big to allocate from the stack. Adaptive Server dynamically allocates and frees memory during the task’s runtime.

The heap memory pool dramatically reduces the predeclared stack size for each task, while also improving the efficiency of memory usage in the server. The heap memory the task uses is returned to the heap memory pool when the task is finished.

Microsoft describes a heap for their SQL Server 2008 R2 as a table without a clustered index. Heaps have one row in sys.partitions, with index_id = 0 for each partition used by the heap. By default, a heap has a single partition. When a heap has multiple partitions, each partition has a heap structure that contains the data for that specific partition. For example, if a heap has four partitions, there are four heap structures; one in each partition.

5348 questions
8542
votes
28 answers

What and where are the stack and heap?

Programming language books explain that value types are created on the stack, and reference types are created on the heap, without explaining what these two things are. I haven't read a clear explanation of this. I understand what a stack is. But,…
921
votes
19 answers

Why should C++ programmers minimize use of 'new'?

I stumbled upon Stack Overflow question Memory leak with std::string when using std::list, and one of the comments says this: Stop using new so much. I can't see any reason you used new anywhere you did. You can create objects by…
bitgarden
  • 9,749
  • 3
  • 15
  • 24
622
votes
16 answers

How can building a heap be O(n) time complexity?

Can someone help explain how can building a heap be O(n) complexity? Inserting an item into a heap is O(log n), and the insert is repeated n/2 times (the remainder are leaves, and can't violate the heap property). So, this means the complexity…
GBa
  • 14,931
  • 15
  • 47
  • 67
520
votes
23 answers

Which is faster: Stack allocation or Heap allocation

This question may sound fairly elementary, but this is a debate I had with another developer I work with. I was taking care to stack allocate things where I could, instead of heap allocating them. He was talking to me and watching over my shoulder…
Adam
  • 24,261
  • 23
  • 72
  • 87
464
votes
10 answers

How is the default max Java heap size determined?

If I omit the -Xmxn option from the Java command line then a default value will be used. According to Java documentation "the default value is chosen at runtime based on system configuration" What system configuration settings influence the…
Richard Dorman
  • 21,020
  • 12
  • 42
  • 48
319
votes
16 answers

java.lang.OutOfMemoryError: GC overhead limit exceeded

I am getting this error in a program that creates several (hundreds of thousands) HashMap objects with a few (15-20) text entries each. These Strings have all to be collected (without breaking up into smaller amounts) before being submitted to a…
PNS
  • 17,431
  • 26
  • 86
  • 131
300
votes
27 answers

Could not reserve enough space for object heap

I am getting the following exception repeatedly each time I try to run the program. Error occurred during initialization of VM Could not reserve enough space for object heap Could not create the Java virtual machine. I tried to increase my virtual…
Narendra
  • 5,195
  • 9
  • 34
  • 54
291
votes
15 answers

What do I use for a max-heap implementation in Python?

Python includes the heapq module for min-heaps, but I need a max heap. What should I use for a max-heap implementation in Python?
Douglas Mayle
  • 18,173
  • 7
  • 40
  • 57
242
votes
7 answers

How do I analyze a .hprof file?

I have a production server running with the following flag: -XX:+HeapDumpOnOutOfMemoryError Last night it generated a java-38942.hprof file when our server encountered a heap error. It turns out that the developers of the system knew of the flag but…
Nick Stinemates
  • 36,669
  • 20
  • 56
  • 60
232
votes
9 answers

Find running median from a stream of integers

Possible Duplicate: Rolling median algorithm in C Given that integers are read from a data stream. Find median of elements read so far in efficient way. Solution I have read: We can use a max heap on left side to represent elements that are…
Luv
  • 4,873
  • 8
  • 42
  • 57
232
votes
14 answers

Priority queue in .Net

I am looking for a .NET implementation of a priority queue or heap data structure Priority queues are data structures that provide more flexibility than simple sorting, because they allow new elements to enter a system at arbitrary intervals. It is…
Doug McClean
  • 13,739
  • 4
  • 43
  • 68
229
votes
12 answers

What is memory fragmentation?

I've heard the term "memory fragmentation" used a few times in the context of C++ dynamic memory allocation. I've found some questions about how to deal with memory fragmentation, but can't find a direct question that deals with it itself. …
AshleysBrain
  • 20,705
  • 15
  • 81
  • 119
192
votes
8 answers

Heap vs Binary Search Tree (BST)

What is the difference between a heap and BST? When to use a heap and when to use a BST? If you want to get the elements in a sorted fashion, is BST better over heap?
kc3
  • 3,943
  • 6
  • 18
  • 14
190
votes
4 answers

Using HeapDumpOnOutOfMemoryError parameter for heap dump for JBoss

I was told I can add the -XX:+HeapDumpOnOutOfMemoryError parameter to my JVM start up options to my JBoss start up script to get a heap dump when we get an out of memory error in our application. I was wondering where this data gets dumped? Is it…
EdC
190
votes
9 answers

Why are two different concepts both called "heap"?

Why are the runtime heap used for dynamic memory allocation in C-style languages and the data structure both called "the heap"? Is there some relation?
Andrey Fedorov
  • 7,836
  • 20
  • 63
  • 95
1
2 3
99 100