By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,494 Members | 1,079 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,494 IT Pros & Developers. It's quick & easy.

Size

P: n/a
Roy
I have an object with array of some data types. How do I get the number of
bytes for it in managed code? The underlying data types could be primitive
types or userdefined structures.
For example I have an integer array boxed in object.
Mar 9 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Roy,

Without hooking into the debugging interfaces that the CLR exposes, it's
impossible to say. While you could marshal these to unmanaged memory, the
amount of memory of a representation in unmanaged memory is not always
guaranteed to be the same as the object in managed memory.

Of course, some things are easy to figure out (int, long, byte, for
example), but overall, it's really not possible.

What are you trying to do?

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Roy" <Ro*@discussions.microsoft.com> wrote in message
news:86**********************************@microsof t.com...
I have an object with array of some data types. How do I get the number of
bytes for it in managed code? The underlying data types could be primitive
types or userdefined structures.
For example I have an integer array boxed in object.

Mar 9 '06 #2

P: n/a
Hi,

"Roy" <Ro*@discussions.microsoft.com> wrote in message
news:86**********************************@microsof t.com...
I have an object with array of some data types. How do I get the number of
bytes for it in managed code? The underlying data types could be primitive
types or userdefined structures.
For example I have an integer array boxed in object.


That's not a simple task,I do remember somebody asked this last week (or the
week before) take a look in the archives. The thread subject was
"Calculating size in bytes of the contents a datastructure"

What r u trying to do?
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Mar 9 '06 #3

P: n/a
Roy
Nicholas,
I have a function taking an object type as a parameter. The object could
actually be a single value or structure of primitive values. It could also be
array of primitive values or structures. The elements in the array have the
same type though. Now the function needs to change the array in byte [] so
that it could be save as a varbinary in database. I tried to use
Marshal.Copy(...) to copy the data to the byte array. However it takes the
size as the 3rd parameter. How do I get the size?
Thanks.
Roy

"Nicholas Paldino [.NET/C# MVP]" wrote:
Roy,

Without hooking into the debugging interfaces that the CLR exposes, it's
impossible to say. While you could marshal these to unmanaged memory, the
amount of memory of a representation in unmanaged memory is not always
guaranteed to be the same as the object in managed memory.

Of course, some things are easy to figure out (int, long, byte, for
example), but overall, it's really not possible.

What are you trying to do?

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Roy" <Ro*@discussions.microsoft.com> wrote in message
news:86**********************************@microsof t.com...
I have an object with array of some data types. How do I get the number of
bytes for it in managed code? The underlying data types could be primitive
types or userdefined structures.
For example I have an integer array boxed in object.


Mar 9 '06 #4

P: n/a
Roy,

Instead of doing that, why not mark your structures as serializable,
then serialize to a MemoryStream. Then, you can get the length of the
stream and know how much space you need in your database.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Roy" <Ro*@discussions.microsoft.com> wrote in message
news:37**********************************@microsof t.com...
Nicholas,
I have a function taking an object type as a parameter. The object could
actually be a single value or structure of primitive values. It could also
be
array of primitive values or structures. The elements in the array have
the
same type though. Now the function needs to change the array in byte [] so
that it could be save as a varbinary in database. I tried to use
Marshal.Copy(...) to copy the data to the byte array. However it takes the
size as the 3rd parameter. How do I get the size?
Thanks.
Roy

"Nicholas Paldino [.NET/C# MVP]" wrote:
Roy,

Without hooking into the debugging interfaces that the CLR exposes,
it's
impossible to say. While you could marshal these to unmanaged memory,
the
amount of memory of a representation in unmanaged memory is not always
guaranteed to be the same as the object in managed memory.

Of course, some things are easy to figure out (int, long, byte, for
example), but overall, it's really not possible.

What are you trying to do?

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Roy" <Ro*@discussions.microsoft.com> wrote in message
news:86**********************************@microsof t.com...
>I have an object with array of some data types. How do I get the number
>of
> bytes for it in managed code? The underlying data types could be
> primitive
> types or userdefined structures.
> For example I have an integer array boxed in object.


Mar 9 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.