2013年10月7日星期一

java static variables are placed in a heap memory or stack memory ?

java static variables are placed in a heap memory or stack memory ?
------ Solution ---------------------------------------- ----
heap area :
1. storage of all objects, each object contains a corresponding class information . (class aims to get the operating instructions )
2.jvm only a heap (heap) shared by all threads , heap does not store basic types and object references , only stores the object itself
stack area :
1. Each thread contains a stack area , the stack saves only basic data types of objects and custom object references ( not an object ) , objects are stored in the heap area
2. Each stack data ( primitive types and object references ) are private , others can not access the stack .
3. stack is divided into three parts: the basic types of variables, and the execution environment context , operational instructions District ( store operating instructions ) .
method area :
1. called static area , with the heap , as shared by all threads . Method area contains all the class and static variables.
2. Methods area are included in the whole process is always unique elements, such as class, static variables.

------ Solution ------------------------------------ --------
static variable in the method area, but either method area may be located on the heap and stack (not java stack ) on
------ Solution ---- ----------------------------------------
learning
- ---- Solution -------------------------------------------- < br>
static variable in the global zone ( static area ) :
global variables and static variables in one , then initialize global variables and static variables in an uninitialized static variables and not placed adjacent one .
then
stack area is stored function parameters , local variables is equivalent ----- compiler automatically allocated and deallocated
heap area is your new objects. ---- Programmers allocation and release .

------ Solution ------------------------------------ --------

on the static area ah
------ Solution -------------------- ------------------------
in the method area and heap area stack area is almost, knowledge Duties different. . .
------ Solution ---------------------------------------- ----
you Tube where he
------ Solution ---------------------------- ----------------
heap memory
------ Solution ------------------- -------------------------

is this , java memory is divided into four , one is a heap , used to store the new object , one stack for storing local variables , then that is a static variable area , storage constants, static variables, and code area , storage code, so it is said that static variables and stack areas are juxtaposed , not subordinate . < br> ------ Solution ----------------------------------------- ---
studied . . .
------ Solution ---------------------------------------- ----
are generally placed on the heap
------ Solution -------------------------- ------------------

do not belong . Static area is a separate area , and heap . Stacks parallel . When the class is loaded only run once, and the heap is putting the object , the stack generally put references , and variables. Look below you will know :


public class TestStatic {
static {
System.out.println("static ");
}
public TestStatic (){
System.out.println("duixiang");
}
public static void main(String[] args) {
new TestStatic();
}

}
/*
 static 
duixiang

 */

------ Solution ------------------------------------- -------
1 floor, said very clearly ; therefore concluded that the non- heap area is also non- stack area .

If you press the second floor of view, it is also heap area also stack area ...
------ Solution --------------- -----------------------------
program is run, the data we had better be aware of where to save . Particular attention is intrinsic distribution , there are six places you can save the data :
1, register. This is the fastest storage area , because it is stored in different ways , and all other places: inside the processor . However , the number of registers is limited, so registers are allocated by the compiler according to need . We have no direct control over , it is impossible to find in your program registers exist any trace .
2, the stack. Reside in the conventional RAM (Random Access Memory) area . But through its " stack pointer " was handled directly supported. If the stack pointer is moved down , it will create a new memory ; moved up to release that memory. This is an extremely fast and efficient data storage method, the second register. When creating the program , java compiler must know exactly all the data stored within the stack "length " and " there is a time ." This is because it must generate the appropriate code to move the cursor up and down . This limitation will undoubtedly affect the flexibility of the program , so even though some java data to be stored in the stack - in particular, object handles , but do not put them java object .
3, heap. A conventional use of the memory pool ( also in the RAM area ) , which holds the java objects. And stack different: the " heap " or " pile " the most attractive place in that the compiler does not have to know how much storage space is allocated from the heap , do not know the data stored in the heap stay much longer. Therefore, when data is saved with the heap will get greater flexibility. Asked to create an object, you simply use the new command code that can be compiled collide . Implementation of these codes, the data will be automatically saved heap . Of course , to achieve this flexibility will inevitably pay a price : the storage space allocated on the heap will spend a longer time
4, static storage . Here, "static " means " in a fixed position ." Program is running , the static data stored will be ready to wait for calls. Available static keyword indicates that a particular element of an object is static. But java objects themselves are never placed in static storage space.
5, constant storage . Constant value is usually placed directly inside the program code . Doing so is safe. Because they never change , and some constant need for strict protection , so you can consider placing them in read-only memory (ROM).
6, non- RAM memory . If the data is fully independent of the outside of a program , the program is not running, still exists and outside the control of the program . Two of the most important example is the " flow objects" and " fixed object ." For Stream object , the object becomes a byte stream , usually issued to another machine , and for a fixed object , the object stored in the disk . Even if the program is halted, and they still maintain their status quo . For these types of data storage, a particularly useful technique is that they can be present in other media , if necessary, or be able to restore them to a normal RAM-based objects.

------ Solution ------------------------------------ --------
static variable discharge side of the pile .
------ Solution ---------------------------------------- ----
learn .
------ Solution ---------------------------------------- ----
static variables into the data area is not placed on the stack and heap , java memory allocation landlord needs to understand again , this mix is very easy to remember , and I hope the landlord can spend more in this area some time , heap memory is cut data storage objects can not be shared , so this is not possible, stack memory jvm will run out at any time clean out the process so it is impossible to give the GC put this inside, static variables have their own separate memory space and some called variable area and some called the data area
------ Solution ---------------------- ----------------------
learned
------ Solution ------------- -------------------------------
static area , and in their classes stored in the same location
- ----- Solution --------------------------------------------
constant area ? ? ? Speaking from the system does not have this stuff ! Only constant pool ! Constant pool where ? ? Not in the method area
------ For reference only --------------------------------- ------
Where
------ For reference only -------------------------- -------------
static area where it belongs ? Heap memory or stack memory ?
------ For reference only -------------------------------------- -
Supreme
------ For reference only -------------------------------- -------
learned
------ For reference only -------------------------- -------------
heap among ,
------ For reference only ------------------ ---------------------
good cattle x answer ah ! ! Queer Dramas ah
------ For reference only --------------------------------- ------
lz casually looking for a virtual machine on je able to read the article ! Do not know send me information
------ For reference only -------------------------------- -------
first , java there is no concept of static variables , do not believe in yourself method defined inside a static int i = 0; java , only static member variables. It belongs to the class attribute . As he put there ? Upstairs is a static area. I do not know in the end there is no such translation . But deep inside jvm Yes translate the method area . Virtual machine architecture : the heap , the method area , local method stacks , pc register. The method area is a class to save a template , the heap is putting the instance of the class . The stack is used generally to function calculation . Just find the bottom of the computer books are known. Stack of data, the function will not be executed is stored . This is why the local variables are the same every time . Even give him one , the next time the function is executed or the original look.
------ For reference only -------------------------------------- -
on constant area

lz -depth look at the sun jvm it
------ For reference only --------------------- ------------------
constant region , JAVA programming ideas 4 already said very clearly.
------ For reference only -------------------------------------- -
lz sub remember to give me ah !
------ For reference only -------------------------------------- -
memory is divided into four zones : stack segment, heap segment, data segment, code segment;
stack area storage function parameters and local variables ;
heap area storage object ;
data area storing static variables or string constants ;
code area storage class method ;

So, static variables are stored in the data area
------ For reference only ------------------------ ---------------
27 House said it right !
------ For reference only -------------------------------------- -
explain heap and stack memory : http://java.e800.com.cn/articles/2011/818/1313658548939_1.html
------ For reference only ----- ----------------------------------
static member variables on the heap or the stack ? Neither, on the method area
Java memory is divided into the following pieces :
heap heap [ new out of the space and the array space, storage objects , arrays, data can not be shared ]
native method stacks native method stack [operating system space required for native methods , store local variables quote]
method area method area [ All object data shared area , store static variables and ordinary methods, static methods , constants, string constants ( strictly speaking stored in the constant pool , heap and stack are ) and other types of information , saying that white a class template is saved = 27 F ]
Program Register program counter register [ fastest and smallest one space area allocated by the compiler , we have no direct control over ]
Note: The method area is a separate area , neither the heap , the stack does not belong in the class load time only run once.
actually stack stack into JVM stack ( dynamic link method exports ) and the native method stack.


------ For reference only ---------------------------------- -----

+1

没有评论:

发表评论