if I have an unsafe method that takes in two arrays, performs some
operations and returns; I know that the garbage collector will not
collect objects allocated inside the unsafe method. However, if I'm
calling this method from a main() method of a class which is safe (i.e
managed), will the allocated array (which, suppose, has been allocated
inside the main() method) be collected by the garbage collector after
it's been used? Also, how do we delete heap allocated objects (suppose a
temporary array) from within the unsafe method? Is the unsafe method
treated as a region (term taken from strict Realitime environment) and
discarded by the GC once it's been used (or is it the method stack
that's discarded)? Just making sure I know what my code does before I
implement it :) thanks
-Andre 3 3150
The GC will collect objects in an unsafe block. The trick is to pin the
objects so the GC *doesn't* collect them while you're using them. That's
what the "fixed" block is for. Look up the Fixed block in the help file, and
there's a sample. Once the code gets passed the fixed block, the objects
become unpinned, and the GC is able to collect them on the next round.
-Rob [MVP]
"Andre" <fo********@hot mail.com> wrote in message
news:3F******** ******@hotmail. com... if I have an unsafe method that takes in two arrays, performs some operations and returns; I know that the garbage collector will not collect objects allocated inside the unsafe method. However, if I'm calling this method from a main() method of a class which is safe (i.e managed), will the allocated array (which, suppose, has been allocated inside the main() method) be collected by the garbage collector after it's been used? Also, how do we delete heap allocated objects (suppose a temporary array) from within the unsafe method? Is the unsafe method treated as a region (term taken from strict Realitime environment) and discarded by the GC once it's been used (or is it the method stack that's discarded)? Just making sure I know what my code does before I implement it :) thanks
-Andre
Thanks Rob, that answers my question.
cheers,
-Andre
Rob Teixeira [MVP] wrote: The GC will collect objects in an unsafe block. The trick is to pin the objects so the GC *doesn't* collect them while you're using them. That's what the "fixed" block is for. Look up the Fixed block in the help file, and there's a sample. Once the code gets passed the fixed block, the objects become unpinned, and the GC is able to collect them on the next round.
-Rob [MVP]
"Andre" <fo********@hot mail.com> wrote in message news:3F******** ******@hotmail. com...
if I have an unsafe method that takes in two arrays, performs some operations and returns; I know that the garbage collector will not collect objects allocated inside the unsafe method. However, if I'm calling this method from a main() method of a class which is safe (i.e managed), will the allocated array (which, suppose, has been allocated inside the main() method) be collected by the garbage collector after it's been used? Also, how do we delete heap allocated objects (suppose a temporary array) from within the unsafe method? Is the unsafe method treated as a region (term taken from strict Realitime environment) and discarded by the GC once it's been used (or is it the method stack that's discarded)? Just making sure I know what my code does before I implement it :) thanks
-Andre
I'd have to re-read the specs on the current GC, but the bottom line is that
at some point, everything gets collected.
There is no explicit delete of managed memory.
-Rob
"Andre" <fo********@hot mail.com> wrote in message
news:3F******** ******@hotmail. com... An afterthought - how do I explicitly 'delete' an object from within an unsafe block like in C++? Is there an analogous operation available for that? thanks
-Andre
Andre wrote: One more thing... what if the unsafe code block allocated space larger than 85Kb (i.e a single object was more than 85Kb), this would mean that the GC would store this in the Large Object Space, which isn't collected, and we'll end up with no or little memory? Or is this not the case with unsafe code blocks?
-Andre
Rob Teixeira [MVP] wrote:
The GC will collect objects in an unsafe block. The trick is to pin the objects so the GC *doesn't* collect them while you're using them.
That's what the "fixed" block is for. Look up the Fixed block in the help file, and there's a sample. Once the code gets passed the fixed block, the
objects become unpinned, and the GC is able to collect them on the next round.
-Rob [MVP]
"Andre" <fo********@hot mail.com> wrote in message news:3F******** ******@hotmail. com...
if I have an unsafe method that takes in two arrays, performs some operations and returns; I know that the garbage collector will not collect objects allocated inside the unsafe method. However, if I'm calling this method from a main() method of a class which is safe (i.e managed), will the allocated array (which, suppose, has been allocated inside the main() method) be collected by the garbage collector after it's been used? Also, how do we delete heap allocated objects (suppose
a temporary array) from within the unsafe method? Is the unsafe method treated as a region (term taken from strict Realitime environment) and discarded by the GC once it's been used (or is it the method stack that's discarded)? Just making sure I know what my code does before I implement it :) thanks
-Andre This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Elidel |
last post by:
Is the use of a COM object in a c# program considered 'unsafe' code ?
Does the method that calls the COM object need the 'unsafe' keyword ?
Is code that calls a COM object considered unmanaged?
Is 'unsafe' code the same as unmanaged code ?
|
by: Jon Milner |
last post by:
How do I declare that my code is unsafe? Sorry the help
files at my University have not been installed!
|
by: Bradley1234 |
last post by:
Sorry if this is obvious, but Ill ask...
Is there a new way of using pointer operations in C# ?
Ive got a Deitel book on C# that neither mentions the word "pointer" nor
"unsafe" in the index.
coming from a C/C++ world, pointers make perfect sense, and getting up to
speed on CS, did pointers go away?
|
by: TomHL |
last post by:
hello,
- I have a Bitmap Object named: bmp1
- I already have the numerical values of:red,blue and green colors + I have
the X and Y cordinates.
How do I set the pixel value via safe code on the bmp1 object?
(the pixel location based on the X & Y values and it's color based on the
red,blue and green values the I already have)
|
by: JS |
last post by:
I was writing some routines which could do bitwise boolean operations
on byte arrays, and I ran into what I think is a bug with C#'s unsafe
code. I am pasting a console application below. Can anyone give an
explanation, or has this type of problem been reported already?
Thanks.
using System;
using System.Collections.Generic;
using System.Text;
| |
by: Sergei |
last post by:
Can anyone explain why PostMessage to a Windows Form
is considered unsafe and raises InvalidOperationException?
I can get rid of that setting CheckForIllegalCrossThreadCalls
to false and everything works just fine. Still I feel somewhat
uncomfortable.
Sergei
|
by: =?Utf-8?B?R3JlZyBMYXJzZW4=?= |
last post by:
I'm trying to write a Stored Procedure CLR for SQL Server 2005 to get some
disk information. I have this code working although the assemble has to be
create with "PERMISSION_SET = UNSAFE". Why do I have to create the assembly
with UNSAFE permissions. What can I do to make the PERMISSION_SET =
EXTERNAL_ACCESS.
|
by: pjerald |
last post by:
package test;
import java.util.ArrayList;
public class MyArrayList{
public static void main(String args)
{
ArrayList al = new ArrayList();
al.add("Jerald");
al.add("PJerald");
|
by: colin |
last post by:
Hi, I have a binary sorted tree wich I find my app is spending most of its time in
so I decided to try speed it up a bit ...
I tested converting it from classes to an indexed array of structs so I could use
unsafe pointers, however although it is definatly faster it only manages
about 90 million iterations per second, wich doesnt seem a lot
on my AMD64 3200+ cpu
I have played around with the data size, and made sure ive kept
it within...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
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 we have to send another system
|
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |