sizeof
-
Hi, I'm trying to write a method that is passed an array and do some bit operations. I'm trying to figure out a way to determine the number of bits an element of the arrray. I could hardcode the value but I'd like the flexibility just changing the header and nothing else. int count(Uint16[] data){ //Try to do something like int bitsInCell = sizeof(data[0])*8; //Instead of int bitsInCell = 16; } I'm trying to do it the first way so if I want to sent Uint32, I don't have to search the code for 16 and switch them to 32. Thanks for your comments.
-
Hi, I'm trying to write a method that is passed an array and do some bit operations. I'm trying to figure out a way to determine the number of bits an element of the arrray. I could hardcode the value but I'd like the flexibility just changing the header and nothing else. int count(Uint16[] data){ //Try to do something like int bitsInCell = sizeof(data[0])*8; //Instead of int bitsInCell = 16; } I'm trying to do it the first way so if I want to sent Uint32, I don't have to search the code for 16 and switch them to 32. Thanks for your comments.
You can use the Marshal class, which is defined in System.Runtime.InteropServices, like so:
int bitsInCell = Marshal.SizeOf(data[0]) * 8;
Take care, Tom ----------------------------------------------- Check out my blog at http://tjoe.wordpress.com
-
You can use the Marshal class, which is defined in System.Runtime.InteropServices, like so:
int bitsInCell = Marshal.SizeOf(data[0]) * 8;
Take care, Tom ----------------------------------------------- Check out my blog at http://tjoe.wordpress.com
Warning: Marshal.Sizeof() and sizeof() do not always agree. Try bool !
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google
-
Warning: Marshal.Sizeof() and sizeof() do not always agree. Try bool !
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google
Good point. Technically, Boolean (bool) in C# maps to BOOL (int) in C++. Probably because bool is not used in the Win32 API. Plus, I believe a C++ long in a 64-bit environment will be 64 bits, but the C# int (a.k.a. Int32) is 32-bits.
Take care, Tom ----------------------------------------------- Check out my blog at http://tjoe.wordpress.com
-
You can use the Marshal class, which is defined in System.Runtime.InteropServices, like so:
int bitsInCell = Marshal.SizeOf(data[0]) * 8;
Take care, Tom ----------------------------------------------- Check out my blog at http://tjoe.wordpress.com