473,406 Members | 2,217 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

The System.Char dimension

I've read that the size of char or of the System.Char under .NET is 2
bytes.

Then when I do:

int char_len = Marshal.SizeOf(Type.GetType("System.Char"));

char_len would be 2!

Instead the value is 1!

Where is the error?

Feb 1 '06 #1
5 1710
Read the documentation for Marshal.SizeOf... it's explained there.
--
http://www.kynosarges.de
Feb 1 '06 #2
ok, from MSDN: "The size returned is the actually the size of the
unmanaged type. The unmanaged and managed sizes of an object can
differ."

But how can I take the real size of a TYPE ?

Feb 1 '06 #3

"RicercatoreSbadato" <em***********@yahoo.it> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
ok, from MSDN: "The size returned is the actually the size of the
unmanaged type. The unmanaged and managed sizes of an object can
differ."

But how can I take the real size of a TYPE ?


Why would you want to know?

You can never access the managed type as a piece of memory so it is never
useful to know its size.

The only half-plausible reason is that you want to assess the actual memory
requirements of your class but even then this is impossible for any
reasonably complicated class because of stuff like overheads in library
hashtables which might vary with the data.
Feb 1 '06 #4
Marshal.SizeOf returns the size of the marshaled version of the type.

What you need is this:
sizeof(char)

note however that this is only valid for value types, there is no reliable
way to obtain the size of reference types.

Willy.

"RicercatoreSbadato" <em***********@yahoo.it> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
| I've read that the size of char or of the System.Char under .NET is 2
| bytes.
|
| Then when I do:
|
| int char_len = Marshal.SizeOf(Type.GetType("System.Char"));
|
| char_len would be 2!
|
| Instead the value is 1!
|
| Where is the error?
|
Feb 1 '06 #5
tnx ;)

Feb 2 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Steve Jorgensen | last post by:
Hi all, I'm working on the schema for a database that must represent data about stock & bond funds over time. My connundrum is that, for any of several dimension fields, including the fund name...
19
by: Rafal Dabrowa | last post by:
What does mean such declaration: void f( char (*ptr) ); Is this the same as void f( char **ptr ); or not ?
11
by: miketigerwoods | last post by:
I'm having problems where I need to parse a command line, and place each token from strtok() into an array. I've read here: http://www.phim.unibe.ch/comp_doc/c_manual/C/CONCEPT/arrays.html (at...
12
by: GRoll35 | last post by:
I get 4 of those errors. in the same spot. I'll show my parent class, child class, and my driver. All that is suppose to happen is the user enters data and it uses parent/child class to display...
2
by: Mirandole | last post by:
Salut. Gros problème en C avec les tableaux à plusieurs entrée : #include <math.h> #include <stdio.h> #define maxt 12 #define maxh 50 Void main(int narg, char ** argv) { char tabl; //...
2
by: Nathan Sokalski | last post by:
I have a multidimensional array declared as the following: Dim guesses(14, 5) As Integer I want to assign all values in a specific dimension to another array declared as follows:
5
by: Jackson | last post by:
I have something that is stumping me. I am trying to initialize a 3 dimensional string array with the code below, but it wont compile. Can anyone explain what Im doing wrong?????????????? Im...
21
by: Wisdo | last post by:
Hi All, char to char ** is compile error. why? if i hava a string array. yes. it's not safe and it's better to use vector<stringinstead. but my point is the language feature. char...
1
by: newstips6706 | last post by:
The Operating System of Organic Machines Building your own "KERNEL". --------------------------------------------------------------------------------
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.