The function creates an array of bytes that contains the same binary data as your platform representation of the integer value . In C ++, this can be achieved (for any type indeed) as follows:
int value; // or any type! unsigned char b[sizeof(int)]; unsigned char const * const p = reinterpret_cast<unsigned char const *>(&value); std::copy(p, p + sizeof(int), b);
Now b is an array with as many bytes as the size of type int (or whatever type you use).
In C #, you need to say fixed to get a raw pointer, since you usually donβt have raw pointers to C # because of objects that do not have a fixed location in memory - the garbage collector can move them at any time. fixed prevents this and fixes the object in place, so the original pointer may make sense.
source share