Linked Questions

14 votes
3 answers
4k views

How much memory does a C# reference consume? [duplicate]

How much memory does a C# reference consume? Does References consumes memory as much as the object itself?
Louie Almeda's user avatar
  • 5,546
-1 votes
1 answer
1k views

Allocate memory to variable in c# [duplicate]

I have the following lines of code: SomeClass a; SomeClass b = new SomeClass(); SomeClass c = new SomeClass() { Foo="sss", Bar="dddd" }; Whats the size (in memory) of the class instances a, ...
mehrdad hajiaghazadeh's user avatar
0 votes
0 answers
79 views

Is a reference write always atomic? [duplicate]

According to this question: How big is an object reference in .NET? , .Net references are 32bit on x86 and 64bit on x64. When a 64bit reference is written is it done atomically or as 2 separate 32bit ...
ConditionRacer's user avatar
1 vote
0 answers
49 views

What size is the pointer to the class? [duplicate]

public class PersonClass { public string Name; public string Name1; public string Name2; public byte Age; public byte Age1; public byte Age2; } I ...
Evgeniy Terekhin's user avatar
21 votes
6 answers
12k views

sizeof() equivalent for reference types?

I'm looking for a way to get the size of an instance of a reference type. sizeof is only for value types. Is this possible?
John Sheehan's user avatar
  • 77.9k
6 votes
5 answers
5k views

c# reference variable mem allocation

Does anyone know how much memory is taken up when you create a reference type variable? String s = "123"; How much memory would 's' take up as a reference, not the data pointing to it?
user avatar
10 votes
1 answer
6k views

How many bytes of memory does each type in .NET consume (32-bit environment)? [closed]

How much memory in bytes do types like int, bool, float, double, decimal, object, and string use when added as a field to an instance of a class?
user1306322's user avatar
  • 8,611
12 votes
4 answers
3k views

Is there any C# analogue of C++11 emplace/emplace_back functions?

Starting in C++11, one can write something like #include <vector> #include <string> struct S { S(int x, const std::string& s) : x(x) , s(s) { } int ...
Constructor's user avatar
  • 7,373
4 votes
2 answers
2k views

Best way for memory to pass method parameters

I am experiencing some memory performance issues with my code and I am not sure which is the best way to pass parameters to my methods. I will give a short example about this. I have for instance ...
Clock's user avatar
  • 984
0 votes
1 answer
542 views

Memory performance IList<T> vs List<T> property

I'm writing a class where I have a collection of objects of class A and I'm writing a function similar to Dictionary<TKey,TValue>.TryGetValue(TKey,TValue) It looks pretty similar to this: ...
cap29's user avatar
  • 904
-1 votes
2 answers
642 views

Initializing ListView, why can't I do this?

As an old C++ programmer I am struggling with some C# issues. I want to reduce the redundancy in setting up a ListView. So I tried the code below. I get a null reference error, but I do not ...
RussK2txb's user avatar
0 votes
2 answers
216 views

Tagged pointer for .NET (C#) object reference

I learned that an object reference of .NET (C#) is just a pointer. My questions are: Is the address of the object aligned depending on the CPU architecture and/or the object's size? If the above is ...
Shigure's user avatar
  • 403
1 vote
1 answer
376 views

How is memory allocated for a C# class?

I have a class like this, public class Cube { private int[,] data; public Cube() { data[,] = new int[3,3]; data[0,0] = 1; data[1,0] = 2; // etc } ...
peter's user avatar
  • 13.3k
0 votes
1 answer
74 views

Is there a difference in memory allocation when declaring a new array in a class? [closed]

Is there a difference in memory usage / allocation for the class myObjectA and myObjectB? For example if I don't want to add a velocity to every object of that class will is use more memory having ...
Patrik Fröhler's user avatar
-3 votes
1 answer
67 views

What is an Object which is not an instance and vice versa? [duplicate]

I am trying to understand the difference between the object and instance and in some forums it is mentioned as same and in other it is mentioned as different. Q.1 If we instantiate 4 different ...
supernatural's user avatar
  • 1,157