
You wonder about the amount of memory occupied by the decimal value type in the C# language and the .NET Framework. The decimal type is a value type and it requires more memory than most other value types that are used commonly.
First, this program demonstrates that the byte size of the decimal type is equal to 16 bytes. It does through a simple simulation that measures the number of bytes allocated in the managed heap before and after an array of decimal[] is allocated. For this reason, we can be assured that the decimal type is 16 bytes in size.
This C# program tests the memory usage of the decimal data type.
Program that measures array of decimals [C#]
using System;
class Program
{
const int _count = 1000000; // One million decimals
static void Main()
{
long bytes1 = GC.GetTotalMemory(true);
//
// Allocate an array of decimal values.
// ... Assign an element to make the allocation not optimized out.
//
decimal[] array = new decimal[_count];
long bytes2 = GC.GetTotalMemory(true);
array[1] = 0.1M;
//
// Compute the memory usage of the decimal type.
//
long difference = bytes2 - bytes1;
double per = (double)difference / _count;
Console.WriteLine("Program used: {0:0.0} MB",
(double)difference / (1024 * 1024));
Console.WriteLine("Each decimal element required: {0:0.0} bytes",
per);
}
}
Output
Program used: 15.3 MB
Each decimal element required: 16.0 bytes
Description. This program text is defined in a compilation unit and it executes the Main entry point at runtime. The GC.GetTotalMemory method is used to acquire an estimate of the number of bytes allocated in the managed heap. The program allocates an array of one million decimal type elements and assigns to it to ensure the allocation is not optimized out or garbage collected before we can measure the memory usage.
16 bytes used. The program when executed on a 32-bit Windows operating system will report that 15.3 MB of memory is used total in the managed heap. Using division, we can determine that 16.0 bytes exactly are used for each decimal element in the array. The program thus proves that each decimal element occupies 16 bytes on the managed heap and the decimal is a 16-byte value type.

The sizeof operator in the C# language can be used on value types to return the number of bytes stored in the value type. If you run a program that evaluates sizeof(decimal), you will see that it returns the integer 16. This article demonstrates this through an experiment and proves that the value is accurate when the type is stored as an element in a large array.
Sizeof
The decimal type is used in cases where high accuracy of values is required, and also large numbers are common. For this reason, currencies and monetary values are often used with the decimal type. Because the decimal type is 16 bytes, it will not be as efficient in low-level code as the native integer. However, when the accuracy of monetary sums is at risk, reduced performance is much preferable.

We looked at the memory usage and byte size of the decimal type in the C# programming language and .NET Framework. Because the decimal type is from the base class library, you can also use it in VB.NET and it will also be 16 bytes there. The decimal type is useful for large and accurate value representations such as for monetary values. The decimal type will occupy four times more memory than an integer, so can impose constraints on some systems that must process huge quantities of data.
Decimal Examples .NET Framework Info