Re: Palette Quantization without unsafe code

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Bob Powell [MVP] (bob_at__spamkiller_bobpowell.net)
Date: 08/11/04


Date: Wed, 11 Aug 2004 16:06:52 +0200

There's a difference between unsafe code which enables C# programs to access
memory directly via pointers and marshaling between managed and unmanaged
memory.

The Marshal class is the correct way to access unmanaged memory locations
from managed code and is suitable for any .net language, not just C#.

You may be confused over the issue of garbage collection. The ability of
Marshal to access unmanaged memory does not make that memory managed or
cause it to become subject to garbage-collection. Marshal itself is subject
to garbage collection but it can access any memory, even that which isn't
subject to GC control.

-- 
Bob Powell [MVP]
Visual C#, System.Drawing
The Image Transition Library wraps up and LED style instrumentation is
available in the June of Well Formed for C# or VB programmers
http://www.bobpowell.net/currentissue.htm
Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm
The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml
Bob's Blog: http://bobpowelldotnet.blogspot.com/atom.xml
"MattB" <MBaskey2002@yahoo.co.uk> wrote in message
news:b4a90122.0408110054.7c3669a9@posting.google.com...
> As I understand it using the Marshall class is essentially doing
> unmanaged code.  Is the code I write using Marshall have the benefits
> of safe, managed code, such as garbage collection, etc?
>
> Thanks,
> Matt
>
>
> "Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:<eraioZxfEHA.140@TK2MSFTNGP12.phx.gbl>...
> > The unsafe code is a lazy way of doing it and very convenient for old
C++
> > programmers. Anything you can do in unsafe code can be done with the
Marshal
> > class anyway.
> >
> > Take a look at the GDI+ FAQ. It has examples where C# uses unsafe code
and
> > the VB uses the Marshal class. Just google on my site for "Marshal."
> >
> > -- 
> > Bob Powell [MVP]
> > Visual C#, System.Drawing
> >
> > The Image Transition Library wraps up and LED style instrumentation is
> > available in the June of Well Formed for C# or VB programmers
> > http://www.bobpowell.net/currentissue.htm
> >
> > Answer those GDI+ questions with the GDI+ FAQ
> > http://www.bobpowell.net/gdiplus_faq.htm
> >
> > The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
> > Windows Forms Tips and Tricks RSS:
http://www.bobpowell.net/tipstricks.xml
> > Bob's Blog: http://bobpowelldotnet.blogspot.com/atom.xml
> >
> >
> >
> >
> >
> >
> > "MattB" <MBaskey2002@yahoo.co.uk> wrote in message
> > news:b4a90122.0408100838.3da845c6@posting.google.com...
> > > I have seen
> > > http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q319061
> > > and
> > >
> >
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/colorquant.asp
> > >
> > > Is there anyway to do this without unsafe code???
> > >
> > >
> > > Thanks,
> > > Matt


Relevant Pages

  • Re: Structure size directives
    ... to do with portable C code, it might trigger a core dump on ... non-x86 CPU. ... emit the code necessary to marshall the data. ... Today, memory is cheap, and we ...
    (comp.lang.c)
  • Re: Palette Quantization without unsafe code
    ... As I understand it using the Marshall class is essentially doing ... Anything you can do in unsafe code can be done with the Marshal ... > available in the June of Well Formed for C# or VB programmers ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: constraints in algebra instead of calculus
    ... Marshall wrote: ... except that at one time it all seemed crystal-clear and I'm not ... sure now whether my memory is bad or whether I was flat-out wrong to ...
    (comp.databases.theory)