- 浏览: 248044 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (127)
- vim (3)
- python (44)
- pymysql (1)
- mysql (9)
- macvim (1)
- erlang (3)
- twisted (0)
- tornado (5)
- django (7)
- postgresql (5)
- sql (1)
- java (7)
- tech (4)
- cache (1)
- lifestyle (3)
- html (1)
- ubuntu (2)
- rabbitmq (1)
- algorithm (8)
- Linux (4)
- Pythonista (1)
- thread (1)
- sort (6)
- 设计模式 (1)
- search (1)
- Unix (6)
- Socket (3)
- C (2)
- web (1)
- gc (1)
- php (10)
- macos (1)
最新评论
-
2057:
这个程序有bug。
查找算法学习之二分查找(Python版本)——BinarySearch -
dotjar:
NB
一个Python程序员的进化[转]
Stack:
Heap:
Stack
Heap
Java中的Heap和Stack。
Java的堆是一个运行时数据区,类的对象从中分配空间。这些对象通过new建立,它们不需要程序代码来显式的释放。堆是由垃圾回收(garbage colloctor)来负责的,堆的优势是可以动态地分配内存大小,生存期也不必事先告诉编译器,因为它是运行时动态分配内存的,Java的垃圾收集器会自动回收这些不再使用的数据。但缺点点,由于要运行时动态分配内存,所欲存取速度较慢。
栈的优势在于,存取速度比堆块,仅次于寄存器,栈数据可以共享。但缺点是,存在栈中的数据大小与生存期必须是确定的,缺乏灵活性。
栈中主要存放一些基本的数据类型和对象句柄。
whats the difference between .equals and ==?
Java的数据类型:
分类简单数据类型和复合数据类型
1、Java中针对Long型
不能使用==进行简单的比较。
==操作比较的是两个变量的值是否相等,对于引用变量表示的是两个变量在堆中存储的地址是否相同,即栈中的内容是否相同。
equals操作便是的两个变量是否是同一个对象的引用,即堆中的内容是否相同?
eg.
参考资料:
http://stackoverflow.com/questions/79923/what-and-where-are-the-stack-and-heap
http://wiki.answers.com/Q/What_is_difference_between_heap_memory_and_stack_memory
http://android.blog.51cto.com/268543/50100
http://blog.csdn.net/snowqoo/article/details/2455605
http://www.cnblogs.com/zhxhdean/archive/2011/03/25/1995431.html
引用
* Stored in computer RAM just like the heap.
* Variables created on the stack will go out of scope and automatically deallocate.
* Much faster to allocate in comparison to variables on the heap.
* Implemented with an actual stack data structure.
* Stores local data, return addresses, used for parameter passing
* Can have a stack overflow when too much of the stack is used. (mostly from inifinite (or too much) recursion, very large allocations)
* Data created on the stack can be used without pointers.
* You would use the stack if you know exactly how much data you need to allocate before compile time and it is not too big.
* Usually has a maximum size already determined when your program starts
* Variables created on the stack will go out of scope and automatically deallocate.
* Much faster to allocate in comparison to variables on the heap.
* Implemented with an actual stack data structure.
* Stores local data, return addresses, used for parameter passing
* Can have a stack overflow when too much of the stack is used. (mostly from inifinite (or too much) recursion, very large allocations)
* Data created on the stack can be used without pointers.
* You would use the stack if you know exactly how much data you need to allocate before compile time and it is not too big.
* Usually has a maximum size already determined when your program starts
Heap:
引用
* Stored in computer RAM just like the stack.
* Variables on the heap must be destroyed manually and never fall out of scope. The data is freed with delete, delete[] or free
* Slower to allocate in comparison to variables on the stack.
* Used on demand to allocate a block of data for use by the program.
* Can have fragmentation when there are a lot of allocations and deallocations
* In C++ data created on the heap will be pointed to by pointers and allocated with new or malloc
* Can have allocation failures if too big of a buffer is requested to be allocated.
* You would use the heap if you don't know exactly how much data you will need at runtime or if you need to allocate a lot of data.
* Responsible for memory leaks
* Variables on the heap must be destroyed manually and never fall out of scope. The data is freed with delete, delete[] or free
* Slower to allocate in comparison to variables on the stack.
* Used on demand to allocate a block of data for use by the program.
* Can have fragmentation when there are a lot of allocations and deallocations
* In C++ data created on the heap will be pointed to by pointers and allocated with new or malloc
* Can have allocation failures if too big of a buffer is requested to be allocated.
* You would use the heap if you don't know exactly how much data you will need at runtime or if you need to allocate a lot of data.
* Responsible for memory leaks
Stack
引用
Often a function or method calls another function which in turn calls another function etc.
The execution of all those functions remains suspended until the very last function returns its value.
All the information required to resume the execution of these functions is stored on the stack.
In particular, local variables are stored on the stack.
Local variables are often stored for short amounts of time while a function/method block uses them to compute a task.
Once a function/method has completed its cycle, the space on the stack used by all local variables is freed.
This chain of suspended function calls is the <b>stack</b>, because elements in the stack (function calls) depend on each other.
The stack is important to consider in exception handling and thread executions.
The execution of all those functions remains suspended until the very last function returns its value.
All the information required to resume the execution of these functions is stored on the stack.
In particular, local variables are stored on the stack.
Local variables are often stored for short amounts of time while a function/method block uses them to compute a task.
Once a function/method has completed its cycle, the space on the stack used by all local variables is freed.
This chain of suspended function calls is the <b>stack</b>, because elements in the stack (function calls) depend on each other.
The stack is important to consider in exception handling and thread executions.
Heap
引用
The heap is simply the memory used by programs to store global variables.
Element of the heap (variables) have no dependencies with each other and can always be accessed randomly at any time.
All global variables are stored in heap memory.
All variables dynamically created by the program with "new()" or "malloc()" or similar commands are also stored on the heap.
In some programming languages, all instances of an object, including all the attributes of that instance, are stored on the heap.
In those programming languages, local variables of a function that have object type are implemented as creating the new object on the heap,
and storing a reference to that object in the local variable, which is on the stack.
When that function exits, the heap memory used by each local variable that has object is freed, and then all the stack used by that stack is freed.
Element of the heap (variables) have no dependencies with each other and can always be accessed randomly at any time.
All global variables are stored in heap memory.
All variables dynamically created by the program with "new()" or "malloc()" or similar commands are also stored on the heap.
In some programming languages, all instances of an object, including all the attributes of that instance, are stored on the heap.
In those programming languages, local variables of a function that have object type are implemented as creating the new object on the heap,
and storing a reference to that object in the local variable, which is on the stack.
When that function exits, the heap memory used by each local variable that has object is freed, and then all the stack used by that stack is freed.
Java中的Heap和Stack。
Java的堆是一个运行时数据区,类的对象从中分配空间。这些对象通过new建立,它们不需要程序代码来显式的释放。堆是由垃圾回收(garbage colloctor)来负责的,堆的优势是可以动态地分配内存大小,生存期也不必事先告诉编译器,因为它是运行时动态分配内存的,Java的垃圾收集器会自动回收这些不再使用的数据。但缺点点,由于要运行时动态分配内存,所欲存取速度较慢。
栈的优势在于,存取速度比堆块,仅次于寄存器,栈数据可以共享。但缺点是,存在栈中的数据大小与生存期必须是确定的,缺乏灵活性。
栈中主要存放一些基本的数据类型和对象句柄。
whats the difference between .equals and ==?
Java的数据类型:
分类简单数据类型和复合数据类型
- 简单数据类型:简单数据类型是不能再简化的、内置的数据类型,由编程语言定义,表示真实的数字、字符和整数。
- 复合数据类型:由简单数据类型的组合形成的更大、更复杂的数据类型。例如类、接口和数字。
1、Java中针对Long型
不能使用==进行简单的比较。
==操作比较的是两个变量的值是否相等,对于引用变量表示的是两个变量在堆中存储的地址是否相同,即栈中的内容是否相同。
equals操作便是的两个变量是否是同一个对象的引用,即堆中的内容是否相同?
eg.
Long userId = 12222222222l; Long commentId = 12222222222l; System.out.println(userId==commentId); System.out.println(userId.equals(commentId));
参考资料:
http://stackoverflow.com/questions/79923/what-and-where-are-the-stack-and-heap
http://wiki.answers.com/Q/What_is_difference_between_heap_memory_and_stack_memory
http://android.blog.51cto.com/268543/50100
http://blog.csdn.net/snowqoo/article/details/2455605
http://www.cnblogs.com/zhxhdean/archive/2011/03/25/1995431.html
发表评论
-
whats the difference between .equals and ==?
2013-09-25 14:59 988Java的数据类型: 分类简单数据类型 复合数据类型 简 ... -
Java判断字符串为空
2013-09-12 18:43 986str==null || str.equals(& ... -
Jave garbage collection
2013-07-08 22:54 2429什么是垃圾回收(garbage collection) Gar ... -
Java Garbage Collection
2013-07-05 18:16 2Garbage Collection垃圾回收 ... -
Java String Stringbuffer Stringbuilder
2013-07-01 22:14 910引用Mutability Difference: Strin ... -
IO复用(select和poll)简介
2013-03-26 00:03 1979Contains: 1、select 2、pol ... -
IO 模型
2013-03-21 21:54 939Unix下可用的5种I/O模型: 1、阻塞式IO 2、非阻塞 ... -
标准IO
2013-03-17 13:14 1217标准I/O的的操作则是围绕stream进行的。 当用标准I/ ... -
Socket简介
2013-03-16 12:54 1388引用A network socket is an endpoi ... -
File descriptor(FD)
2013-03-16 00:43 2299Contains: 1、FD 2、fcntl 3、dup、du ... -
jsp页面定时刷新的方法
2010-11-09 11:09 18711.利用Javascript对整个页面的刷新 functi ... -
JSP页面传递中文参数时乱码
2010-11-08 23:52 957设置 request.setCharacterEncoding ...
相关推荐
The stack and heap are areas of memory used to support functions and dynamic memory allocation, respectively. Pointers are complex enough to deserve more in-depth treatment. This book provides that ...
Specifying stack and heap using the scatter file The ARM C library provides multiple implementations of the function __user_setup_stackheap(), and can select the correct one for you automatically ...
In this chapter, we think about stack and heap memory. Chapter 4, Lists, Lists, and More Lists, covers the first data structures: lists. Using several examples, this chapter goes into variations of ...
We'll work through core network hacking concepts and advanced Windows exploitation techniques, such as stack and heap overflows, precision heap spraying, and kernel exploitation, using coding ...
We program in high-level languages for ... And perhaps we prefer solving problems strictly through an abstract quasi-mathematical algorithmic language without taking machine architecture into account.
BoundsChecker automatically pinpoints static, stack and heap memory errors, and resource leaks. Unlike ordinary memory-checking tools, BoundsChecker validates the latest Windows APIs including ...
在IT领域,尤其是在操作系统与编程语言的运行时环境中,“运行时堆和栈”(The Run-time Heap and Stack)是理解程序内存管理的核心概念。本文旨在深入解析这一主题,结合提供的部分文档内容,详细阐述堆和栈的区别...
深入理解堆(Heap)与栈(Stack):变量声明背后的故事 在计算机科学领域,堆(Heap)与栈(Stack)是两种常见的内存管理方式,它们在程序运行时扮演着至关重要的角色。本文将深入探讨堆与栈的概念、工作原理以及...
在一些平台上,在有些情况下,javacore也被称为javadump,它包含jvm和应用程序相关的在特定时刻的一些诊断信息,如操作系统,应用程序环境,线程,native stack本地堆,锁,和内存的信息。在生成heapdump文件的时候...
In later chapters, students learn to implement fundamental data structures such as lists, stacks, queues, and trees in a language that fosters their understanding of stack- and heap-dynamic memory ...
- **Unique and Global Link Key Type Configuration**:这些宏定义允许用户配置独特的或全球性的链接密钥类型,从而增强了系统的灵活性和安全性。 - **Backwards Interoperability**:这一节介绍如何确保旧版本的...
C++ has stack memory and heap memory. You need to control where you want to put your objects. It has constructors and destructors. You need to know when and how they are called. Then it has multiple ...
Stack Binary Heap Fibonacci Heap Priority Queue (list based) Bubble sort Selection sort Insertion sort Radix sort Quick sort Merge sort Heap sort Double linked list Skip list Self-organized linked-...
Whenever a method is invoked a new stack frame is added to the stack and corresponding frame is removed when its execution is completed. Native method stack: holds the state of each native method ...
We will be looking into a linked list, stack, queue, trees, heap, hash table and graphs. We will be looking into sorting, searching techniques. Then we will be looking into algorithm analysis, we ...
Learn the basics of programming, stack operations, buffer overflow and heap vulnerabilities, and exploit development Test and exploit systems using Metasploit and other tools Break in to Windows and...
- **The Stack and the Heap**: Explains the difference between stack-allocated and heap-allocated memory and their respective uses. - **Garbage Collection**: Discusses how the .NET runtime ...
Upgrading To Z-Stack v2.0.0 Upgrading To Z-Stack v2.1.0 Upgrading To Z-Stack v2.4 ...Z-Stack Monitor and Test API Z-Stack API Z-Stack Compile Options 802.15.4 MAC API OSAL API HAL Driver API ...
以及“scatter-load file declares no heap or stack regions and __user_initial_stackheap is not defined”错误,这表明链接器未能找到`Main`符号或堆栈和堆的定义。解决此问题,通常在完成步骤1后,如果代码中...