With regard to a declaration like: Dim myIntArray As Integer = new Integer(6)
Jesse Liberty, in _Programming Visual Basic .NET, 2nd Edition_
(O'Reilly) says:
While VB.NET arrays are reference types, created on the heap, the elements of an array are allocated based on their type. Thus, myIntArray is a reference type allocated on the heap, and the integer elements in myIntArray are value types, allocated on the stack. (While you can box a value type so that it can be treated like a reference type, as explained in Chapter 6, it is not necessary or desirable to box the integers in an array.) By contrast, an array that contains reference types, such as Employee or Button, will contain nothing but references to the elements, which are themselves created on the heap.
Question:
Is that true? And if so, what happens when you return and the stack
gets popped, while a reference to the array created on the heap may
still exist somewhere? 3 1102
June 16, 2005
Seems to be a bit more complicated than needed! :-)
--
Joseph Bittman
Microsoft Certified Application Developer
Web Site: http://71.35.110.42
Dynamic IP -- Check here for future changes
"David Harmon" <so****@netcom.com> wrote in message
news:42***************@news.west.earthlink.net... With regard to a declaration like:
Dim myIntArray As Integer = new Integer(6)
Jesse Liberty, in _Programming Visual Basic .NET, 2nd Edition_ (O'Reilly) says:
While VB.NET arrays are reference types, created on the heap, the elements of an array are allocated based on their type. Thus, myIntArray is a reference type allocated on the heap, and the integer elements in myIntArray are value types, allocated on the stack. (While you can box a value type so that it can be treated like a reference type, as explained in Chapter 6, it is not necessary or desirable to box the integers in an array.) By contrast, an array that contains reference types, such as Employee or Button, will contain nothing but references to the elements, which are themselves created on the heap.
Question: Is that true? And if so, what happens when you return and the stack gets popped, while a reference to the array created on the heap may still exist somewhere?
David,
I assume that the writer explains this. If it is only written to impress the
reader with the knowledge of the writer, than I know what I have to do with
such a book.
For me this is in the part why .Net has managed code. What you ask is
managed by the framework. For me the only important in this that things on
the stack are immutable, and therefore have to be created every time again
on a new place (on that stack) when the format changes (for a string is that
with every change), while objects are mostly only references of references
and therefore very dynamic.
For using something there is no difference with something on the stack or in
an object. When there is no reference anymore than an object can exist,
however for an object, the managed code takes care to release it on a
proper time and you cannot reach it anymore even before that. (While the
stack is removed (probably not really but only decremented with one), every
time that the procedure where it is created in, goes out of scope).
For me is the only part in this that we have to remember, that every time
that when things have to be new created that than consumes processing time.
I hope this gives an idea.
Cor This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Andrew |
last post by:
I'm afraid I don't know PHP well enough
to figure this out.
What I would like is to keep an array in
memory so that it doesn't have to be
reloaded each time a .php script is run.
Is this...
|
by: Jack Hughes |
last post by:
This argument has come up two or three times lately.
We have a web standards document at our company that say "Use valid
HTML 4; We don't recommend switching to DIV-based CSS-P for layout
just...
|
by: Walter Dnes (delete the 'z' to get my real address |
last post by:
I've noticed a few threads (full of sound and fury, signifying
nothing) here recently about allocation of large memory blocks. I'm
about to start on a personal pet project where I'll be using...
|
by: Luis Arvayo |
last post by:
Hello,
I am trying to convert a jpeg image stored in a PictureBox to a byte array
in order to later save it to a database, but I get this error : "Generic
Error in GDI+".
The source code is...
|
by: Eric Sabine |
last post by:
Below is a sub I have which contains 4 lines of code. I would like to
reduce it to 1. My problem is that it takes 3 lines to create the array to
hold the sql parameter and since there's only one...
|
by: Tim Chase |
last post by:
While working on a Jumble-esque program, I was trying to get a
string into a character array. Unfortunately, it seems to choke
on the following
import random
s = "abcefg"
random.shuffle(s)
...
|
by: Tim Streater |
last post by:
I have some items, numbered from 0 upwards. Some of them may have a
string attached. All these items need to be represented in a single
already existing database record. So, I thought of taking an...
|
by: 010 010 |
last post by:
I found this very odd and maybe someone can explain it to me.
I was using fread to scan through a binary file and pull bytes out. In
the middle of a while loop, for no reason that i could...
|
by: Frank-O |
last post by:
Hi ,
Recently I have been commited to the task of "translating" some complex
statistical algorithms from Matlab to C++. The goal is to be three
times as fast as matlab ( the latest) .
I've...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |