Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
Select your favorite languages :
  • Or search :

Idiom #109 Number of bytes of a type

Set n to the number of bytes of a variable t (of type T).

using System.Runtime.InteropServices;
int n = Marshal.SizeOf(t);
int n = sizeof(T);
int n;
unsafe
{
    n = sizeof(T);
}
N : Integer := (T'Size + 7) / 8;
n = sizeof (t);
#include <cstddef>
std::size_t n = sizeof(t);
auto n = T.sizeof;
use iso_c_binding
n = c_sizeof(i)
import "reflect"
var t T
tType := reflect.TypeOf(t)
n := tType.Size()
n := SizeOf(T);
use Devel::Size qw(total_size);
my $n = total_size $t;
import pympler.asizeof
n = pympler.asizeof.asizeof(t)
require 'objspace'
n = ObjectSpace.memsize_of(t)
let n = ::std::mem::size_of::<T>();

New implementation...
< >
programming-idioms.org