Linked Questions
18 questions linked to/from Memory address of an object in C#
-3 votes
1 answer
209 views
Is it possible to get a reference's value? [duplicate]
Objects are "passed by value" (and not "passed by reference" as some people may think) where the value is the reference. Just out of complete curiosity, is it possible to get the value of this ...
-1 votes
1 answer
614 views
How do I get the address inside the reference of an object [duplicate]
I have a class called Person class Person { public string name; public int age; public Person(string name, int age) { this.name = name; this.age = age; } } I ...
39 votes
5 answers
26k views
Using string as a lock to do thread synchronization
While i was looking at some legacy application code i noticed it is using a string object to do thread synchronization. I'm trying to resolve some thread contention issues in this program and was ...
12 votes
5 answers
23k views
Get Memory Address of .NET Object (C#)
I am trying to track down a bug in the mono runtime where a variable appears to be allocated to one valid object, and then is reassigned later to a bogus object, specifically //early in code I ...
8 votes
3 answers
1k views
Is there a way to align objects in C# same way as in C++ to avoid false sharing?
I am a C++ habitat working on a C# project. I have encountered the following situation. I have class MyClass and want to avoid any 2 objects of type MyClass ever to share a cache line even if I have ...
0 votes
6 answers
400 views
Comparing C# object
Consider this code: object str1 = "shahrooz"; object str2 = "shahrooz"; object int1 = 1; object int2 = 1; Console.WriteLine("str1 == str2 : " + (str1 == str2)); Console.WriteLine("int1 == int2 : " + ...
4 votes
1 answer
4k views
pointer to a array of type generic? [duplicate]
I'd like to create a generic method that uses a pointer to an array of T where T could be a C# primitive, or a C# class. I was going along fine until I attempted the "T" part. Is there a way around ...
3 votes
5 answers
273 views
Reference object comparison of type string
Consider the following code: public static void Main() { string str1 = "abc"; string str2 = "abc"; if (str1 == str2) { Console.WriteLine("True"); } else { ...
4 votes
3 answers
1k views
.Net equivalent of Java's System.identityHashCode()
Java's System.identityHashCode() Returns the same hash code for the given object as would be returned by the default method hashCode(), whether or not the given object's class overrides hashCode(...
1 vote
3 answers
1k views
How to get a pointer to memory of Array instance?
There are many examples over the net how to get pointer to byte[] or int[,], i.e. when you know exactly the element type and rank of the array. But how to get the pointer for generic Array? The main ...
3 votes
1 answer
2k views
Get memory address of field using reflection (C#)
In .Net Core how do you get the memory address (IntPtr) of a primitive field when the parent object is not known at compile time? If the object class was a struct and blittable then I could use ...
2 votes
3 answers
834 views
C# Memory address extension with code
I got following MemoryAddressExtenstion code, it shows object address in C# Want to know what is IntPtr** and **(IntPtr**) Thanks public static class MemoryAddressExtenstion { public static ...
1 vote
2 answers
2k views
Get Memory Address of Loaded Assemblies
I need to get memory address of loaded assemblies in my appdomain. When Assemblies are loaded in to a .Net app , they will be fully loaded in main application memory. If we search a memory for this ...
2 votes
1 answer
297 views
NullReferenceException thrown but the object passed the null check, how is that possible?
I'm using the AddEventHandler method from that answer, but when doing it on an EventHandler with a value type argument that happens: using System.Reflection; public class Program { public static ...
2 votes
1 answer
1k views
Is there a default ID assigned to any object instance in .NET? [duplicate]
Possible Duplicate: .NET unique object identifier Instead of re-inventing the wheel, is there a unique, immutable object ID I can access for each object instance in .NET? I'm asking this because ...