Getting size of a data structure
-
I'm writing a program and I need to figure out how big any single data structure is but the programs' signature simply allows any thing of "object" type because I want to allow anything. How can I figure out how many bytes whatever is sent to the program is long? I tried looking at sizeof and stuff but it appears sufficiently different from C so I'm stuck and it requires
unsafe
which doesn't seem like the best thing. I can't find anything using the Type class with <obj>.GetType() or typeof(<obj>). I've done searches and I guess my problem is too general to search so I'm stuck. This object can be a byte, character, string or an instance of a custom class or anything at all. I want to be as unrestrictive as possible. If it can't be done easily or at all, I'll probably revert back to C but I'm trying to learn C#. Thanks in advance, Nate. -
I'm writing a program and I need to figure out how big any single data structure is but the programs' signature simply allows any thing of "object" type because I want to allow anything. How can I figure out how many bytes whatever is sent to the program is long? I tried looking at sizeof and stuff but it appears sufficiently different from C so I'm stuck and it requires
unsafe
which doesn't seem like the best thing. I can't find anything using the Type class with <obj>.GetType() or typeof(<obj>). I've done searches and I guess my problem is too general to search so I'm stuck. This object can be a byte, character, string or an instance of a custom class or anything at all. I want to be as unrestrictive as possible. If it can't be done easily or at all, I'll probably revert back to C but I'm trying to learn C#. Thanks in advance, Nate.Search for overloading, that sounds like what you are trying to do.
-
I'm writing a program and I need to figure out how big any single data structure is but the programs' signature simply allows any thing of "object" type because I want to allow anything. How can I figure out how many bytes whatever is sent to the program is long? I tried looking at sizeof and stuff but it appears sufficiently different from C so I'm stuck and it requires
unsafe
which doesn't seem like the best thing. I can't find anything using the Type class with <obj>.GetType() or typeof(<obj>). I've done searches and I guess my problem is too general to search so I'm stuck. This object can be a byte, character, string or an instance of a custom class or anything at all. I want to be as unrestrictive as possible. If it can't be done easily or at all, I'll probably revert back to C but I'm trying to learn C#. Thanks in advance, Nate.What exactly are you trying to do? Why do you want to know the size of objects, are you doing custom marshalling of any sort? Regards Senthil _____________________________ My Blog | My Articles | WinMacro
-
Search for overloading, that sounds like what you are trying to do.
I know how to overload class and operators but that's not the goal. I'll state what I'm trying to do in the other thread so I only write it once.
-
What exactly are you trying to do? Why do you want to know the size of objects, are you doing custom marshalling of any sort? Regards Senthil _____________________________ My Blog | My Articles | WinMacro
I'm trying to read the size and then get to the bits of any instance of data so I can teach it to a neural network. That way I can not only teach it strings, but also pictures for facial recognition, or other things, like maybe voice, or I can use it for error correction. I'm sure someone else has done it but I'm trying to learn C# and this is my project. If no one else has, I'll likely make it my first submission on here for others to see. I've seen "marshall" in class roots on help pages but I don't know what that is.
-
I'm trying to read the size and then get to the bits of any instance of data so I can teach it to a neural network. That way I can not only teach it strings, but also pictures for facial recognition, or other things, like maybe voice, or I can use it for error correction. I'm sure someone else has done it but I'm trying to learn C# and this is my project. If no one else has, I'll likely make it my first submission on here for others to see. I've seen "marshall" in class roots on help pages but I don't know what that is.
Did you try Marshal.SizeOf[^]? Regards Senthil _____________________________ My Blog | My Articles | WinMacro
-
Did you try Marshal.SizeOf[^]? Regards Senthil _____________________________ My Blog | My Articles | WinMacro
Looks promising at a glance. I've been looking into just what marshaling is about and it's starting to gel, and this will help, thanks. Looking at the Marshal class seems to be just what I'm looking for, accessing the raw data.