473,568 Members | 2,820 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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("S ystem.Char"));

char_len would be 2!

Instead the value is 1!

Where is the error?

Feb 1 '06 #1
5 1718
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

"RicercatoreSba dato" <em***********@ yahoo.it> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.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.

"RicercatoreSba dato" <em***********@ yahoo.it> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.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("S ystem.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
3722
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 itself, the dimension may be represented in different ways over time, and may split or combine from one period to the next. When querying from...
19
3458
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
8972
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 bottom) that you can access a char by doing char and getting the string. However when I try the code below I get error: invalid use of array with...
12
10062
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 it. here is the 4 errors. c:\C++\Ch15\Employee.h(29): error C2440: '=' : cannot convert from 'char ' to 'char '
2
2741
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; // tableaux de chaînes
2
4557
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
7800
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 going crazy with this one! Ive tried a 2 dimensional array minus the "test3" and it works fine. public string screens; screens = new string{...
21
2277
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 sex = {"Male", "Female" };
1
1925
by: newstips6706 | last post by:
The Operating System of Organic Machines Building your own "KERNEL". --------------------------------------------------------------------------------
0
7693
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7916
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8117
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7660
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7962
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6275
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5217
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3651
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1207
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.