- Heap Functions
- What is the “standard” size of the stack and the heap in a C program?
- 2 Answers 2
- Set default heap size in Windows [duplicate]
- 2 Answers 2
- What is the maximum Java heap size I can use safely on Windows 64-bit platform?
- 3 Answers 3
- Maximum heap size using for Java process in Windows 10 64 bit running 64 bit JVM
- 4 Answers 4
Heap Functions
Each process has a default heap provided by the system. Applications that make frequent allocations from the heap can improve performance by using private heaps.
A private heap is a block of one or more pages in the address space of the calling process. After creating the private heap, the process uses functions such as HeapAlloc and HeapFree to manage the memory in that heap.
The heap functions can also be used to manage memory in the process’s default heap, using the handle returned by the GetProcessHeap function. New applications should use the heap functions instead of the global and local functions for this purpose.
There is no difference between memory allocated from a private heap and that allocated by using the other memory allocation functions. For a complete list of functions, see the table in Memory Management Functions.
A thread should call heap functions only for the process’s default heap and private heaps that the thread creates and manages, using handles returned by the GetProcessHeap or HeapCreate function.
The HeapCreate function creates a private heap object from which the calling process can allocate memory blocks by using the HeapAlloc function. HeapCreate specifies both an initial size and a maximum size for the heap. The initial size determines the number of committed, read/write pages initially allocated for the heap. The maximum size determines the total number of reserved pages. These pages create a contiguous block in the virtual address space of a process into which the heap can grow. Additional pages are automatically committed from this reserved space if requests by HeapAlloc exceed the current size of committed pages, assuming that the physical storage for it is available. Once the pages are committed, they are not decommitted until the process is terminated or until the heap is destroyed by calling the HeapDestroy function.
The memory of a private heap object is accessible only to the process that created it. If a dynamic-link library (DLL) creates a private heap, it does so in the address space of the process that called the DLL. It is accessible only to that process.
The HeapAlloc function allocates a specified number of bytes from a private heap and returns a pointer to the allocated block. This pointer can be used in the HeapFree, HeapReAlloc, HeapSize, and HeapValidate functions.
Memory allocated by HeapAlloc is not movable. The address returned by HeapAlloc is valid until the memory block is freed or reallocated; the memory block does not need to be locked.
Because the system cannot compact a private heap, it can become fragmented. Applications that allocate large amounts of memory in various allocation sizes can use the low-fragmentation heap to reduce heap fragmentation.
A possible use for the heap functions is to create a private heap when a process starts up, specifying an initial size sufficient to satisfy the memory requirements of the process. If the call to the HeapCreate function fails, the process can terminate or notify the user of the memory shortage; if it succeeds, however, the process is assured of having the memory it needs.
Memory requested by HeapCreate may or may not be contiguous. Memory allocated within a heap by HeapAlloc is contiguous. You should not write to or read from memory in a heap except that allocated by HeapAlloc, nor should you assume any relationship between two areas of memory allocated by HeapAlloc.
You should not refer in any way to memory that has been freed by HeapFree. After the memory is freed, any information that may have been in it is gone forever. If you require information, do not free memory containing the information. Function calls that return information about memory (such as HeapSize) may not be used with freed memory, as they may return bogus data.
The HeapDestroy function destroys a private heap object. It decommits and releases all the pages of the heap object, and it invalidates the handle to the heap.
What is the “standard” size of the stack and the heap in a C program?
I have read that the «standard» and initial stack size on Linux is
8MB and Windows is
But how does the heap allocation work? Does the OS set a «virtual» size to the process heap like it does for the stack with committed and reserved memory?
2 Answers 2
Classically, the layout of a program has the ‘text’ (or ‘code’) segment at the low end of memory, followed by the fixed data (‘data’ and ‘bss’ segments), followed by a gap, with the stack growing downwards from high memory. The gap in the middle becomes the heap, which grows from the end of the data towards the stack.
Things are more complex with threaded programs, shared libraries loaded, shared memory, etc.
The initial stack size is o/s dependent. The initial heap size is logically zero, but tends to grow almost immediately (as the program and the shared libraries are loaded).
There is no general «standard size». Individual operating systems will have a default size, but usually they can be altered with appropriate parameters in the program image or on the command line.
C executes in a vast range of systems from tiny microprocessors with only a few hundred bytes of available memory to gigantic processor arrays with hundreds of gigabytes.
In your larger systems (including most Windows and Linux environments) the stack and heap will be assigned to segments that can be expanded, so that physical memory for maximum sizes does not need to be pre-reserved. Many micros, though, lack memory mapping hardware and the sizes must be pre-reserved (though sometimes the stack and heap are made to grow towards each other so that there’s only one common limit).
Set default heap size in Windows [duplicate]
I want to set Java heap size permanently and don’t want to run every jar file with options. I use Windows and Java 1.7.
2 Answers 2
Setup JAVA_OPTS as a system variable with the following content:
After that in a command prompt run the following commands:
This can be explained as follows:
- allocate at minimum 256MBs of heap
- allocate at maximum 512MBs of heap
These values should be changed according to application requirements.
You can also try adding it through the Environment Properties menu which can be found at:
- From the Desktop, right-click My Computer and click Properties.
- Click Advanced System Settings link in the left column.
- In the System Properties window click the Environment Variables button.
- Click New to add a new variable name and value.
- For variable name enter JAVA_OPTS for variable value enter -Xms256m -Xmx512m
- Click ok and close the System Properties Tab.
- Restart any java applications.
JAVA_OPTS is a system variable that stores various settings/configurations for your local Java Virtual Machine. By having JAVA_OPTS set as a system variable all applications running on top of the JVM will take their settings from this parameter.
To setup a system variable you have to complete the steps listed above from 1 to 4.
What is the maximum Java heap size I can use safely on Windows 64-bit platform?
We use Windows 2003 server 64-bit for running a WebSphere/J2EE application (JVM is also 64-bit). The machine has 16GB physical memory. It’s unfortunately that our application is memory-intensive, and it would still take some time for us to add additional memory.
I understand operating system itself requires certain amount of memory. That being said, what would be a safe (without paging?) maximum heap size we can use, assuming this is the sole application running on the system?
3 Answers 3
I think that the answer will depend on many factors, many of which are hard to predict.
IMO, the most practical way to determine the safe max heap size is by trial and error. I’d start with a max heap size of around 15Gb, look at the system’s memory / paging stats, and adjust up or down.
The best idea is to experiment. Check the first answer here. it will help you.
You can write a batch file to do experiment for different heap sizes and see where it crashes.
If you have two memory banks e.g. as you have two CPUs, you may find that your application performance is significantly slower if you use more than half your memory. You will get the best performance from your memory if you use about 3/4 of your memory bank size.
You may still get better performance for using more of your memory, but it won’t scale the way you might expect and your GC times will jump significantly.
Maximum heap size using for Java process in Windows 10 64 bit running 64 bit JVM
What is maximum Heap size for Java process running on Windows 10 64 bits, with 64 bits JVM? My machine has 8 GB of RAM. And I am running Java 8. I trying to run BFS on huge graph for experimental purposes. While running BFS I am monitoring Heap size being used in Java Visual VM. According to Visual VM heap utilization is always less than 2000 MB regardless of providing following JVM parameters
I did some research over internet but could not find any specific answer related to the system specification I am using. Can a java process use more than 2 GB on Windows 10 64 bit and 64 bit JVM? As Guidelines for Java Heap sizing the limit for Windows XP/2008/7 is 2 GB.
4 Answers 4
On a 64-bit machine, with 64-bit JVM you can work with multi gigabyte heaps (dozens and dozens of GBs). I’m not sure it’s limited in any way except by the available memory (and the theoretical address space of a 64-bit pointer).
Of course if you’re working with a huge heap, the GC has a lot more work to do and you may find that you need to scale horizontally instead of vertically, to maintain a good performance.
If VisualVM isn’t showing you using more than 2GB (the initial heap size given with -Xms ), then it probably just doesn’t need more than that. You’ve given the permission to use up to 3GB ( -Xmx ), but the JVM won’t allocate more memory just for the fun of it.
Maximum Heap can be allocated for 32bit JVM is 2^32 = 4G, Again 4gb will be devided into 1+ GB for VM to use for runtime classes. It varies windows it is
2GB and linux it is
3GB. As you are using 64bit machine maximum heap available is 2^64 it will be big enough for you to run BFS easily.
You can monitor the available memory using vm flags «-XX+PrintFlagsFinal | grep -iE HeapSize» will tell you the maximum available heap size that can be used. Configure slightly less than that and start using.
There is no definite size you could specify for 64 bit architecture but simple test helps you find what is the maximum contiguous space available or could be allocated for a process. This could be tested as follow by using simple command. Try as below java -Xmx -version If the above command gives result then your system could be allowed to have Xmx to that level, If it fails then you can’t specify that value.
Few test from system. I tested the value with 20G.40g,100G,160G,300G all these gave java -version output but tried with 1600G that throws the error. Output of the test C:\Users\mpalanis>java -Xmx300G -version
java version «1.7.0_80» Java(TM) SE Runtime Environment (build 1.7.0_80-b15) Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)
C:\Users\mpalanis>java -Xmx1600G -version
Error occurred during initialization of VM Unable to allocate 52431424KB bitmaps for parallel garbage collection for the requested 1677805568KB heap.
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.