heap

dynamically increasing java heap space

别等时光非礼了梦想. 提交于 2019-12-30 04:24:07
问题 I have written a java program that tests the speed of a couple of multi-threading algorithms on different machines with various numbers of processors. On some machines, merge sort* fails because it requires a sizable heap space to work on very large arrays. I can easily change the java heap space myself before running the program, but I feel like a more robust and easy approach would be to do this task from within the program itself. Is there a way to request/achieve more heap space from the

Java memory Management for JNI

吃可爱长大的小学妹 提交于 2019-12-30 03:31:07
问题 I have two questions : What if I have a JNI call to a method and the JNI method leaks memory. Once this method completes will the JVM Garbage collector be able to get that memory back. I heard that the JVM does not manage the Heap Space used by JNI ? But the memory used by JNI is a part of the memory used by the Java process ? Is it absolutely necessary to use JNI to achieve IPC ? What are the other popular Java techniques or is there a Open Source Library to achieve Shared memory in Java ?

If I allocate memory in one thread in C++ can I de-allocate it in another

拥有回忆 提交于 2019-12-30 01:59:10
问题 If I allocate memory in one thread in C++ (either new or malloc) can I de-allocate it in another, or must both occur in the same thread? Ideally, I'd like to avoid this in the first place, but I'm curious to know is it legal, illegal or implementation dependent. Edit: The compilers I'm currently using include VS2003, VS2008 and Embedded C++ 4.0, targetting XP, Vista, Windows 7 and various flavours of Windows CE / PocketPC & Mobile. So basically all Microsoft but across an array of esoteric

What data structure is used to implement the dynamic memory allocation heap?

本小妞迷上赌 提交于 2019-12-29 19:46:10
问题 I always assumed a heap (data structure) is used to implement a heap (dynamic memory allocation), but I've been told I'm wrong. How are heaps (for example, the one implemented by typical malloc routines, or by Windows's HeapCreate , etc.) implemented, typically? What data structures do they use? What I'm not asking: While searching online, I've seen tons of descriptions of how to implement heaps with severe restrictions . To name a few, I've seen lots of descriptions of how to implement:

If the JVM keeps moving objects around when it does GC, how does it resolve references?

瘦欲@ 提交于 2019-12-29 03:27:28
问题 I'm reading on JVM tuning, and it occurred to me that the JVM keeps moving objects around when it does GC. But Java Objects have references to each other, which one would presume are implemented as pointers, but the JVM can't possibly go over the whole heap after every time it moved objects around, and update all the references; surely that would take for ever. So how does it resolve references, if the references do not change, but the physical location of the objects do? I've read a lot

prove that binary heap build max comparsion is (2N-2)

微笑、不失礼 提交于 2019-12-29 01:44:08
问题 I am trying to prove that for binary heaps, buildHeap does at most (2N-2) comparisons between elements. I find it very difficult to prove this claim. 回答1: The build-heap algorithm starts at the midpoint and moves items down as required. Let's consider a heap of 127 items (7 levels). In the worst case: 64 nodes (the leaf level) don't move at all 32 nodes move down one level 16 nodes move down two levels 8 nodes move down three levels 4 nodes move down four levels 2 nodes move down five levels

How to dynamically monitor Java heap size?

巧了我就是萌 提交于 2019-12-28 11:46:31
问题 I am trying to monitor the java heap size dynamically. Does anybody know how to get the maxmium memory used in the process of running a piece of codes? Does the Runtime.maxMemory() do the trick? Thanks 回答1: maxMemory() returns the maximum amount of memory that java will use. So That will not get you what you want. totalMemory() is what you are looking for though. See The docs 回答2: There are a large number of profiler tools available that should help you with this. A popular commercial tool is

How can I implement decrease-key functionality in Python's heapq?

荒凉一梦 提交于 2019-12-28 11:46:05
问题 I know it is possible to realize decrease-key functionality in O(log n) but I don't know how? 回答1: To implement "decrease-key" effectively, you'd need to access the functionality "decrement this element AND swap this element with a child until heap condition is restore". In heapq.py, that's called _siftdown (and similarly _siftup for INcrementing). So the good news is that the functions are there... the bad news is that their names start with an underscore, indicating they're considered

Generate a Java thread dump without restarting.

为君一笑 提交于 2019-12-28 06:44:42
问题 I'd like to create a thread that keeps track of the memory usage and cpu usage. If the application reaches a high level, I want to generate an heap dump or a thread dump. Is there a way to generate a Thread dump runtime without restarting? 回答1: Here's how we do it programmatically: http://pastebin.com/uS5jYpd4 We use the JMX ThreadMXBean and ThreadInfo classes: ThreadMXBean mxBean = ManagementFactory.getThreadMXBean(); ThreadInfo[] threadInfos = mxBean.getThreadInfo(mxBean.getAllThreadIds(),

Fields of class, are they stored in the stack or heap?

99封情书 提交于 2019-12-27 19:12:10
问题 I saw a question yesterday which raised (for me) another question. Please look at the following code: public class Class1 { int A; //as I uderstand, int is value type and therefore lives in the stack } class Class2 { Run() { Class1 instance1 = new Class1(); instance1.A = 10; //it points to value type, but isnt this reference (on heap)? } } Or while creating the instance of Class1, its field types are created on the heap as well? But then I do not understand when it would really be on the