Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Pointer (computer programming)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===C#=== In the [[C Sharp (programming language)|C# programming language]], pointers are supported by either marking blocks of code that include pointers with the <code>unsafe</code> keyword, or by <code>using</code> the <code>System.Runtime.CompilerServices</code> assembly provisions for pointer access. The syntax is essentially the same as in C++, and the address pointed can be either [[Managed code|managed]] or [[Managed code|unmanaged]] memory. However, pointers to managed memory (any pointer to a managed object) must be declared using the <code>fixed</code> keyword, which prevents the [[Garbage collection (computer science)|garbage collector]] from moving the pointed object as part of memory management while the pointer is in scope, thus keeping the pointer address valid. However, an exception to this is from using the <code>IntPtr</code> structure, which is a memory managed equivalent to <code>int*</code>, and does not require the <code>unsafe</code> keyword nor the <code>CompilerServices</code> assembly. This type is often returned when using methods from the <code>System.Runtime.InteropServices</code>, for example: <syntaxhighlight lang="csharp"> // Get 16 bytes of memory from the process's unmanaged memory IntPtr pointer = System.Runtime.InteropServices.Marshal.AllocHGlobal(16); // Do something with the allocated memory // Free the allocated memory System.Runtime.InteropServices.Marshal.FreeHGlobal(pointer); </syntaxhighlight> The [[.NET Framework|.NET framework]] includes many classes and methods in the <code>System</code> and <code>System.Runtime.InteropServices</code> namespaces (such as the <code>Marshal</code> class) which convert .NET types (for example, <code>System.String</code>) to and from many [[Managed code|unmanaged]] types and pointers (for example, <code>LPWSTR</code> or <code>void*</code>) to allow communication with [[Managed code|unmanaged code]]. Most such methods have the same security permission requirements as unmanaged code, since they can affect arbitrary places in memory.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)