heap

Why do we need to create an object in heap?

梦想的初衷 提交于 2019-12-24 19:34:07
问题 why can we use the stack for all our needs? NOTE: it will be very good if you give an example while explaining because it is easier to understand with examples. sorry for bad English. 回答1: In practice the call stack is limited and small. The typical limit is a few megabytes. In contrast, you could often allocate gigabytes in heap memory. (on some systems, you might configure the system to have a larger stack; but you need to tell your users if you need that) Also, and most importantly, the

When is it a bad idea to use a heap for a Priority Queue?

亡梦爱人 提交于 2019-12-24 19:12:14
问题 In the section that explains Dijkstra's Algorithm in the book Introduction to Algorithms by Cormen et. al., while analysing the complexity of the algorithm, they say If the graph is sufficiently sparse ... we can improve the algorithm by implementing the min priority queue with a binary min heap So I was wondering, what is the need for such a statement? Isn't it always wiser to just use heaps for priority queues? 回答1: There are many different ways to implement a priority queue. A binary min

Should I make stack segment large or heap segment large?

耗尽温柔 提交于 2019-12-24 17:35:11
问题 I'm programming a design for a microprocessor with very limited memory and I must use "a lot" of memory in different functions. I can't have a large stack segment, heap segment, data segment, I must choose which to make big and which to make small. I have about 32KB total, I use about 20KB for the text segment, that gives me 12KB for the rest. And I need a buffer of 4KB to pass to different functions (SPI Flash sector size). Where should initialize that large buffer? So my choices are: 1) If

Heap Corruption with malloc, struct and char *

女生的网名这么多〃 提交于 2019-12-24 13:43:03
问题 I seem to have a memory corruption in my C program. I used _ASSERTE( _CrtCheckMemory( ) ); to find the problem statement and it breaks on a line that says scep_conf->engine_str = NULL; right before it. So if I understood it correctly, the malloc before that broke something, right? So this is the part of the code that causes the issue: scep_conf = (SCEP_CONF *) malloc(sizeof(scep_conf)); scep_conf->engine = (struct scep_engine_conf_st *) malloc(sizeof(struct scep_engine_conf_st)); scep_conf-

Heap Violations when releasing a CStringArray& parameter from a DLL exported function

社会主义新天地 提交于 2019-12-24 12:57:20
问题 I have developed a MFC dll containing a function having this prototype: //DLL code long __declspec(dllexport) GetData(CString csIdentifier, CStringArray& arrOfData) { //based on the identifier I must add some strings inside the string array arrOfData.Add("..."); arrOfData.Add("..."); /*.....................*/ return 1; } The problem that I have is after the function gets called (from the executable). The destructor of the arrData will be called and will try to release the memory but it will

Out of memory issue for Hadoop copyFromLocal

笑着哭i 提交于 2019-12-24 11:45:00
问题 I'm trying to copy a directory that contains 1,048,578 files into hdfs file system but, got below error: Exception in thread "main" java.lang.OutOfMemoryError: Java heap space at java.util.Arrays.copyOf(Arrays.java:2367) at java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:130) at java.lang.AbstractStringBuilder.ensureCapacityInternal(AbstractStringBuilder.java:114) at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:415) at java.lang.StringBuffer

Problems uploading base64 images to server by httpPost

…衆ロ難τιáo~ 提交于 2019-12-24 11:04:42
问题 I am prototyping an application where I send the whole content of the local SQLite database to a remote MySQL database using JSON and HttpPost. Everything works fine for text data. Now I added images to the party and I though I could add the images as base64 strings to the JSON I am sending away. My images are 800 x 600 pixels, more or less 500kb in size each. If I paste the JSON generated by my app manually to a web page, it is fine, I get my images and everything else. Using the app

java.lang.OutOfMemoryError : Java heap space

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-24 09:57:12
问题 I was playing with some examples of Collections from Oracle website public class Timing { public static void method(){ List numbers = new ArrayList(); for (double i = 1; i <= Double.MAX_VALUE; i++) numbers.add(new Double(i)); Collections.shuffle(numbers); List winningcombination = numbers.subList(0, 10); Collections.sort(winningcombination); } public static void main(String[] args) { long start = System.currentTimeMillis(); method(); long end = System.currentTimeMillis(); System.out.println(

Hibernate causes out of memory exception when saving large number of entities

梦想的初衷 提交于 2019-12-24 09:41:19
问题 In my application I'm using CSVReader & hibernate to import large amount of entities (like 1 500 000 or more) into database from a csv file. The code looks like this: Session session = headerdao.getSessionFactory().openSession(); Transaction tx = session.beginTransaction(); int count = 0; String[] nextLine; while ((nextLine = reader.readNext()) != null) { try { if (nextLine.length == 23 && Integer.parseInt(nextLine[0]) > lastIdInDB) { JournalHeader current = parseJournalHeader(nextLine);

Out of memory: Heap Size Error after adding 10KB ImageButtons

試著忘記壹切 提交于 2019-12-24 08:49:20
问题 I am working in Eclipse on an android app which starts with a splash screen (suspecting Memory Leak here after some research done). The splash screen goes into the main menu consisting of just 7 buttons which lead to some Java Applet. The whole app was working perfectly until I changed the 7 dummy (ImageButton) png images to the finalized 7 png images. These png images have an average of 10KB and don't think they are the cause of the problem (since they're this small), even though this