这一段是什么意思? [英] What this paragraph mean ?

查看:66
本文介绍了这一段是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好.
我需要有人向我解释本段的含义:

仔细考虑代码后堆中有多少个对象
语句或块执行.考试将使您知道,例如,
前面的代码仅生成一个对象(分配给引用变量的数组
命名线程).线程引用的单个对象包含五个线程引用
变量,但尚未创建线程对象或将其分配给这些引用.

解决方案

含义是:您需要返回课程笔记并再次阅读它们.小心.因为您错过了一些相当基本的概念.

堆栈中存储的内容与堆中存储的内容之间存在很大的区别-这就是该段的含义.这里有更多信息: http://www.sap-img. com/java/difference-between-stack-and-heap.htm [


只是为了提醒您如果忘记了堆栈和堆之间的区别;):

堆栈:
------
像堆一样存储在计算机RAM中.
在堆栈上创建的变量将超出范围并自动取消分配.
与堆中的变量相比,分配要快得多.
用实际的堆栈数据结构实现.
存储本地数据,返回地址,用于参数传递
当使用过多堆栈时,可能会导致堆栈溢出. (主要来自无限(或太多)递归,分配非常大)
在堆栈上创建的数据无需指针即可使用.
如果您确切地知道在编译之前需要分配多少数据并且它不会太大,则可以使用堆栈.
通常,程序启动时已经确定了最大大小

堆:
-----
像堆栈一样存储在计算机RAM中.
必须手动销毁堆上的变量,并且切勿使其超出范围.使用delete,delete []或free
释放数据 与堆栈上的变量相比,分配速度较慢.
按需使用,分配一个数据块供程序使用.
当分配和取消分配很多时会产生碎片
在C ++中,在堆上创建的数据将由指针指向,并使用new或malloc
进行分配. 如果请求分配过多的缓冲区,可能会导致分配失败.
如果您不确切知道运行时需要多少数据或需要分配大量数据,则可以使用堆.
负责内存泄漏


Hello .
i need someone explain to me what this paragraph mean :

Think carefully about how many objects are on the heap after a code
statement or block executes. The exam will expect you to know, for example, that the
preceding code produces just one object (the array assigned to the reference variable
named threads). The single object referenced by threads holds five Thread reference
variables, but no Thread objects have been created or assigned to those references.

What it means is: you need to go back to your course notes and read them again. Carefully. Because you have missed some fairly basic concepts.

There is a biug difference between what is stored on the stack, and what is stored on the heap - and that is what the paragraph is getting at. There is a little more info here:
http://www.sap-img.com/java/difference-between-stack-and-heap.htm[^] but really, you need to review you course so far, and try to understand this text in the light of what you are being taught.


Hi,

Just think about reference and pointers to objects.
A pointer has its own memory address and size on the stack (4 bytes on x86), whereas a reference shares the same memory address but also takes up some space on the stack.
This Means When you create an Object, a memory is allocated on the Heap for the new object, a poiter to this new object is allocated on the stack.
Since a reference has the same address as the original variable itself, it is safe to think of a reference as another name for the same variable.
So the reference would not consume memory of the "Heap".



just to let remind difference between stack and heap if you forgot it ;) :

Stack:
------
Stored in computer RAM 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

Heap:
-----
Stored in computer RAM 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


这篇关于这一段是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆