Pointers in VB

1/12/2005 2:45:34 PM

Pointers in VB

One of my issues with VB was its lack of support for pointers, which are still very useful for such tasks as working with unmanaged code, manipulating image data, constructing a specialized memory manager, and using memory-mapped files.

I just learned that there is an alternative available for the semicolon-challenged through the Marshal class in the System.Runtime.InteropServices namespace. The functions are ReadByte (and ReadInt32 and so on for all the integer types) and WriteByte. There are a few overloads of the function, one that takes an IntPtr and another that takes an object reference.

Of course, calling a method won’t be as fast as using a pointer in C++/C#, unless the runtime optimizes away the call, which I don’t believe is the case. There’s still no convenient analog to referencing inside a struct.






Net Undocumented is a blog about the internals of .NET including Xamarin implementations. Other topics include managed and web languages (C#, C++, Javascript), computer science theory, software engineering and software entrepreneurship.

Social Media