(Sorry, I accidentally posted this to
microsoft.public.dotnet.csharp.general, and I didn't mean to!)
In the following method, a byte array is made, and then passed to
Socket.BeginReceive. The byte array is local. But, presumably,
Socket.BeginReceive creates a reference to it, so the byte array (a
reference) does disappear, but the object the reference 'points' to
(the array data) is referenced by something inside of
Socket.BeginReceive, so all is well when the data receive call back
(DataReceive_CallBack in this case) is called. Right?
public void MyMethod()
{
byte[] bytesArray = new byte[1024];
mySocket.BeginReceive(bytesArray, 0, bytesArray.Length,
SocketFlags.None, DataReceive_CallBack, bytesArray);
}
Zytan 4 1500
>But, presumably, Socket.BeginReceive creates a reference to it, so the byte array (a reference) does disappear, but the object the reference 'points' to (the array data) is referenced by something inside of Socket.BeginReceive, so all is well when the data receive call back (DataReceive_CallBack in this case) is called. Right?
You're right that you don't have to worry about the array object being
garbage collected as long as it's in use.
Mattias
--
Mattias Sjögren [C# MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Zytan <zy**********@yahoo.comwrote:
(Sorry, I accidentally posted this to
microsoft.public.dotnet.csharp.general, and I didn't mean to!)
In the following method, a byte array is made, and then passed to
Socket.BeginReceive. The byte array is local. But, presumably,
Socket.BeginReceive creates a reference to it, so the byte array (a
reference) does disappear, but the object the reference 'points' to
(the array data) is referenced by something inside of
Socket.BeginReceive, so all is well when the data receive call back
(DataReceive_CallBack in this case) is called. Right?
No. The byte array doesn't disappear. The variable "bytesArray"
disappears, but the value of that variable was just a reference. The
byte array itself is on the heap, and isn't local at all.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
You're right that you don't have to worry about the array object being
garbage collected as long as it's in use.
Yes, Mattias, thanks. I just tested and confirmed this.
Zytan
No. The byte array doesn't disappear. The variable "bytesArray"
disappears, but the value of that variable was just a reference. The
byte array itself is on the heap, and isn't local at all.
Hi Jon, yes, exactly. It was your page on parameter passing that
makes it so clear (and also with the addendum with pictures) that
shows why this is the case, but I just had to be sure. I just
finished testing it to be positive.
Thanks
Zytan This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Robert Tarantino |
last post by:
Hello,
I am trying to find a way to create a scheduled task or
service that will copy my local profile folders
under "Documents and settings" to a network drive. This
would allow me to restore...
|
by: Lasse Skyum |
last post by:
I'm currently learning STL and I hate not knowing what is gooing on "inside"
STL... not because I really _need_ to know it to develop my game project,
but that's just my nature... like most of you...
|
by: Steve |
last post by:
Does anyone have any ideas on how to write self-destruct code?
I need to run a one-time procedure the next time a database opens. If the
procedure is successful, the procedure needs to be deleted...
|
by: Brad |
last post by:
I have a win2003 server workstation with multiple webs, each web has it's
own ip address. In VS2005, if I select to open an existing web site, select
Local IIS, the dialog correctly displays a...
|
by: Michal Kwiatkowski |
last post by:
Hi!
I'm building a class that most of methods have similar intro, something
like this:
def method(self):
var_one = self.attr_one
var_two = self.attr_two.another_attr
empty_list =
| |
by: Frederick Gotham |
last post by:
If we have a simple class such as follows:
#include <string>
struct MyStruct {
std::string member;
MyStruct(unsigned const i)
{
|
by: Zytan |
last post by:
I see that static is more restricted in C# than in C++. It appears
usable only on classes and methods, and data members, but cannot be
created within a method itself. Surely this is possible in...
|
by: Chris Thomasson |
last post by:
I am fine-tuning some last minute things in my c++ allocator lib and was
thinking of ways to manage local references to system objects created with
factory functions. I started to tinker around...
|
by: cpluslearn |
last post by:
Hi,
I have a local class inside a function template. I am able to wrap
any type in my local class. Is it legal C++? What type of class is
Local? Is it a class template or regular class?
Thanks...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |
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: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |