Managed C# and Unsafe Code

From: CodeTyro (CodeTyro_at_discussions.microsoft.com)
Date: 01/16/05


Date: Sun, 16 Jan 2005 08:49:04 -0800

My native language being C++, I've got a few questions that a couple of hours
of searching on msdn didn't answer.

First, when using unsafe code and pointers, what is the C# equivalent to the
C++ "delete" command? I would like to keep my memoryspace clean, but I've
been unable to find a way to do it thus far.

Second, I'm using structs to store a specific set of data. Is there a C#
equivalent to the C++ STL "Vector" (or any of the STLs)? I read about sorted
lists, queues, and the like, though they seem to be only strings. Is there a
way to modify the type?

Third, and most important, I've got a bit of code that uses a large number
of pointers. There are six classes, five derived classes from one base. The
base is the only one with pointers ("Base_ *next", for the obvious linked
list structure). The "base" class for the other functions is an "unsafe
public class", but when iI try to call a pointer to this class in a function
within another class (alsoe "unsafe public class") it gives me an error,
"error CS0208: Cannot take the address or size of a variable of a managed
type ('NPCGen.Base_')" I'm at a loss, expecting it to be unmanaged as I
specified "unsafe". How do I set functions to be unmanaged?

-- 
Code - Specifically C++ & C#
Tyro - Novice Apprentice


Relevant Pages

  • Re: What will be the next MAJOR programming language for commercial use?
    ... This probably means that D is unsafe. ... > less safe, and there is no obvious dividing line between the two. ... It happens that most languages with GC are safe or almost safe. ... > for pointers much less than in, say, C, so one rarely has to deal ...
    (comp.lang.misc)
  • Re: Unsafe lack of pointers in C#?
    ... Pointers can be used in unsafe code blocks from C#. ... Find great Windows Forms articles in Windows Forms Tips and Tricks ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Access to driver memory using c#
    ... if you need the unmanaged data to be available as a managed type ... To do this in C# you have two options, or you can use unsafe code pointers, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: using classes vs. modules
    ... However, they are typically unsafe, cannot be checked at compile time, and can thus increase the potential for bugs in the code and exploitation. ... I doubt that a beginner would struggle more with pointers than with OOP. ... I've said you do not need to mention bitmap manipulation as I have already mentioned it. ... I used pointers for years in C, which is one of my favorite programming languages beside BASIC-style languages. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: A failing oif C#?
    ... >>> You can infact mark a section of your c# code unsafe and use pointers ... >> How does one mark a section unsafe and have the code before and after ... >> How does one use pointers at all in C#? ... >> subset of that array to be treated as a structure with data members? ...
    (microsoft.public.dotnet.languages.csharp)