heap

java outOfMemoryError with stringbuilder

▼魔方 西西 提交于 2019-12-18 02:49:48
问题 I'm getting a java outOfMemoryError when I call this method - i'm using it in a loop to parse many large files in sequence. my guess is that result.toString() is not getting garbage collected properly during the loop. if so, how should i fix it? private String matchHelper(String buffer, String regex, String method){ Pattern abbrev_p = Pattern.compile(regex);//norms U.S.A., B.S., PH.D, PH.D. Matcher abbrev_matcher = abbrev_p.matcher(buffer); StringBuffer result = new StringBuffer(); while

Why is the maximum size of the Java heap fixed?

给你一囗甜甜゛ 提交于 2019-12-17 23:33:41
问题 It is not possible to increase the maximum size of Java's heap after the VM has started. What are the technical reasons for this? Do the garbage collection algorithms depend on having a fixed amount of memory to work with? Or is it for security reasons, to prevent a Java application from DOS'ing other applications on the system by consuming all available memory? 回答1: In Sun's JVM, last I knew, the entire heap must be allocated in a contiguous address space. I imagine that for large heap

Memory sharing between C++ threads

风流意气都作罢 提交于 2019-12-17 23:28:19
问题 I'm new to threading in C++, and I'm trying to get a clear picture about how memory is shared/not shared between threads. I'm using std::thread with C++11. From what I've read on other SO questions, stack memory is owned by only one thread and heap memory is shared between threads. So from what I think I understand about the stack vs. the heap, the following should be true: #include <thread> using namespace std; class Obj { public: int x; Obj(){x = 0;} }; int main() { Obj stackObj; Obj

Is there an easy way to make a min heap in C++?

ε祈祈猫儿з 提交于 2019-12-17 22:40:07
问题 I'm very new to C++, and I was wondering if there was a way to make a min heap in C++ from the standard library. 回答1: Use make_heap() and friends, defined in <algorithm> , or use priority_queue , defined in <queue> . The priority_queue uses make_heap and friends underneath. #include <queue> // functional,iostream,ctime,cstdlib using namespace std; int main(int argc, char* argv[]) { srand(time(0)); priority_queue<int,vector<int>,greater<int> > q; for( int i = 0; i != 10; ++i ) q.push(rand()%10

OpenMP: poor performance of heap arrays (stack arrays work fine)

允我心安 提交于 2019-12-17 21:54:29
问题 I am a fairly experienced OpenMP user, but I have just run into a puzzling problem, and I am hopeful that someone here could help. The problem is that a simple hashing algorithm performs well for stack-allocated arrays, but poorly for arrays on the heap. Example below uses i%M (i modulus M) to count every M-th integer in respective array element. For simplicity, imagine N=1000000, M=10. If N%M==0, then the result should be that every element of bins[] is equal to N/M: #pragma omp for for (int

Applet: Java heap space

試著忘記壹切 提交于 2019-12-17 21:30:05
问题 Due to a small implementation mistake I discovered how quickly I could reach a Java heap space issue now the bug is fixed everything is fine but it did get me looking into how to solve this and I foudn multiple solution such as java -Xms5m -Xmx15m MyApp the problem is that this changes the java memory on my computer, but I'm working on a Applet that is going to be used in a webrowser. Therefore, is there a way, at RUNTIME in an APPLET to change the heap size ? 回答1: You can add parameters to

How to change max element in a heap in C++ standard library?

隐身守侯 提交于 2019-12-17 21:29:40
问题 If I have a max heap, and if I need to change the max element, it comes down to a single bubble-down algorithm. Is there any way to do this via the C++ standard library, without coding the algorithm by hand? I understand it should be equivalent to pop_heap + push_heap, but that's 2 bubble down operations instead of just one. So - is this bubble-down algorithm exposed via the library API? 回答1: If you are willing to call std::pop_heap() on your own container v , then you can just first v.push

Missing memory: size of young generation includes only one survivor space

折月煮酒 提交于 2019-12-17 21:19:54
问题 On the Java heap, I expected that the size of the young generation would be the sum of the sizes of the eden space and both of the survivor spaces ( from space and to space ): [young gen size] = [eden space size] + [from space size] + [to space size] However, GC logs (using XX:+PrintHeapAtGC ) state that the size of the young generation is the sum of the sizes of the eden space and only one of the survivor spaces : [young gen size] = [eden space size] + [from space size] Why does the size of

heap data structure via pointers

我与影子孤独终老i 提交于 2019-12-17 21:08:38
问题 Suggest an efficient way to find last position in heap satisfying the following conditions: 1) via pointers not via array 2) where we can insert or delete node I could find it in O(n) time complexity but suggest a way which is of O(logn) or O(1) time complexity. 回答1: I'm assuming here that you mean a binary heap. If you know how many nodes are in the heap, you can find the last node in O(log n) time by converting the count to binary, and then following the path of bits from high to low. That

Using Designated Initializers with the Heap

泄露秘密 提交于 2019-12-17 20:53:21
问题 One can use designated initializers as shown below (for "billy") without issue, but when the same initialization approach is used on dynamic memory things will break at compile-time. What are the restrictions for using designated initializers? Aside from where (i.e. the address) to which we are writing, what makes these two initializations different? Why can we not use designated initializers with dynamic memory? struct student{ char *name; int age; }; void print_student(struct student* st){