heap

C++ stack variables and heap variables

When you create a new object in C++ that lives on the stack, (the way I've mostly seen it) you do this: CDPlayer player; When you create an object on the heap you call new: CDPlayer* player = new CDPlayer(); But when you do this: CDPlayer player=CDPlayer(); it creates a stack based object, but whats the difference between that a...

How to write a template ?

Hello, i need to write a template with Nodes containing data with 2 data structures : a map and a minimum heap, both got the same nodes in it and every 2 same nodes are connected. the problem is that i need the heap to know the node fields for the heapify for example, and i don't know what's the right way to do so, friends? public fields...

heapsort in Matlab

Hey guys. Im trying to write an algorithm for heapsort in Matlab. Its not working. The heap is constructing fine. Filling the sorted vector is not working. Here is the code and thank you! function [xs,h]= heap(x) N = length(x); h = zeros(1,N); N_h = 0; for i=1:N N_h = N_h +1; child = N_h; h(child) = x(i); while child>1 ...

about malloc() and free() in C

I have the following C-code: #include<stdio.h> #include<stdlib.h> typedef struct node { int a; }node; int main() { node * n; printf("\n%d\n",n->a); n = (node *) malloc ( sizeof( node )); printf("\n%d\n",n->a); n->a = 6; printf("\n%d\n",n->a); free(n); printf("\n%d\n",n->a); n->a = 4; pri...

Why does my JVM heap size thrash from 2gigs to 8 gigs?

Heap memory size thrashes between 2gigs and ~8gigs about once a minute (see picture). Relevant details: High traffic site Lots of physical memory Redhat 5.5 Java 1.6.0_07 Glassfish 2.2.1 (yes, I know it's old. no, we can't upgrade. yes, i know it's unusual to use as a production app server). -XX:MaxPermSize=192m -XX:+AggressiveHeap -X...

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. So: What is memory fragmentation? How can I tell if memory fragmentation is a problem for my ap...

Eclipse release heap back to system

Hello, I'm using Eclipse 3.6 with latest Sun Java 6 on Linux (64 bit) with a larger number of large projects. In some special circumstances (SVN updates for example) Eclipse needs up to 1 GB heap. But most of the time it only needs 350 MB. When I enable the heap status panel then I see this most of the time: 350M of 878M I start Eclip...

Watching value types on the stack and objects on heap from within an application

Forgive me If this is a dumb question. Can one programmatically "observe" the contents of stack and heap while an application (say a console app) is running? Are there any APIs which would do this? ...

Stack and Heap Space for Modern Computers

When writing in C, how can I tell how much stack space is available in memory when I launch a program? How about heap space? How can I tell how much memory is being used during the execution of my program? ...

Where does the stack memory allocated to a thread come from?

I have few questions regarding java GC and memory management. In java we define process memory upper bound and lower bound by xmx and xms parameters. Using these parameters JVM allocates young old and perm space. So if new threads are created then from which memory do stacks memory is allocated to threads? is it from perm space or any ...

are the new objets assigned from eden space or eden + fromSurvivor space ?

are the new objets assigned from eden space or eden + fromSurvivor space ? can free space in from survivor space be also used for allocation to new objects ? EDIT : consider the scenerio : suppose Eden space is full and from survivor space occupancy is less, then in that case if new object is created (new object is small enough to fit...

where does a "static final" directly allocated into? young gen or old gen or perm gen?

Is a "static final" directly allocated into young gen or old gen or perm gen? (I guess it will most likely land into old gen over the time I suppose.) If it is allocated in the perm gen then, will it be garbage collected when class unloading takes place in Perm Gen ? ...

Is there any way of preventing application from crashing when heap is corrupted? - C programing language

Hi, Sometimes in execution I get this error message in VS2010 when trying to free memory: Windows has triggered a breakpoint in [APPNAME].exe. This may be due to a corruption of the heap, which indicates a bug in [APPNAME].exe or any of the DLLs it has loaded. This may also be due to the user pressing F12 while [APPNAME].e...

Integer to string in C without preallocated char array

Please, look at the following code that just convert an unsigned int to a string (there may be some unhandled cases but it's not my question), allocating a char array in the heap and returning it, leaving the user the responsibility to free it after the use. Can you explain me why such function (and others similar) do not exist in C sta...

how the live objects are figured out in young generation collection ?

I understand that time taken by YGC is proportional to number of live objects in Eden. I also understand that how the live objects are figured out in Major collections (All the objects in thread stacks and static objects and further objects reachable from those objects transitively.) But I dont understand how the live objects are figu...

what are the effects of paging on garbage collection ?

what are the effects of paging on garbage collection ? ...

Binary Heap vs (new) B-Heap: Should it be implemented in the CLR/.NET, and where?

The following article discusses an alternative heap structure that takes into consideration that most servers are virtualized and therefore most memory is paged to disk. http://queue.acm.org/detail.cfm?id=1814327 Can (or should) a .NET developer implement a B-Heap data structure so that parent-child relationships are maintained within...

Library for Graphing Binary Heaps?

I am doing research with the graphs of binary heaps, and could really use an effective library that can graph binary heaps. I have found a couple different pieces of software (not libraries) that can do this, but some had display problems with large numbers of elements and others could not handle large numbers of elements at all. I wou...

Why does a BufferedImage require so much memory beyond the size of its data array?

I'm trying to determine how much heap any given TYPE_INT_ARGB BufferedImage will use so that, for a program which is doing some image processing, I can set a reasonable max heap based on the size of image we feed it. I wrote the following program as a test, which I then used to determine the least maximum heap under which it would run w...

Algorithms that lead to java.lang.OutOfMemoryError: PermGen space error

I am getting PermGen space error on Sun JVM (1.6.0_21-b06) (Ok, it's Oracle :)). Increasing of option -XX:MaxPermGen value does not help. I know that PermGen is a space intended for permanent objects like class metadata. Count of classes in project is not so big ~ 10 000. Before crash jvisualvm shows 57MB as Used PermGen. I guess that s...