473,503 Members | 2,152 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Size

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
4 1809
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
7084
by: Marti | last post by:
Dear everyone, Its my understanding that IE6 now uses a default text-size of "Small" rather than IE5's "Medium". Since I have used relative font-sizes (usually in ems) on all my sites, I am...
25
7520
by: Matthias | last post by:
Hi, I am just reading that book by Scott Meyers. In Item 4 Meyers suggests to always use empty() instead of size() when probing for emptyness of STL containers. His reasoning is that size()...
9
3754
by: Dr John Stockton | last post by:
Assuming default set-ups and considering all reasonable browsers, whatever that may mean, what should an author expect that his readers in general will see (with visual browsers) for a page with...
2
28525
by: Kums | last post by:
What is the maximum permissible size of a database? Is there any limitation. What is the maximum # of tablespace's allowed in a database? Thanks for your response.
4
3476
by: tshad | last post by:
I am having trouble with links in my DataGrid. I have Links all over my page set to smaller and they are consistant all over the page in both Mozilla and IE, except for the DataGrid. Here is a...
27
31285
by: Deephay | last post by:
Greetings all, I have a program that used the realloc() function to change the allocated size of a buffer, the program works with some arguments, but with some other arguments, it will show me...
8
10145
by: redefined.horizons | last post by:
I would like to have an array declaration where the size of the array is dependent on a variable. Something like this: /* Store the desired size of the array in a variable named "array_size". */...
7
43840
by: carterweb | last post by:
This is how I do it now. 1. Determine the dimensions of the rectangle. 2. Set a my font size to a fixed maximum size. 3. Apply the font my string and measure the string using the graphics...
18
24929
by: Diogenes | last post by:
Hi All; I, like others, have been frustrated with designing forms that look and flow the same in both IE and Firefox. They simply did not scale the same. I have discovered, to my chagrin,...
27
3177
by: 1001 Webs | last post by:
I am trying to make my style sheet as compatible as possible and I'm getting a bit confused here. I've read that the best size for font-size would be 76.1%; due to shortcomings in the way both...
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7287
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7349
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7008
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
4688
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3177
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3168
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1521
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
399
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.