data type representations in .NET

T

Tony Johansson

Hi!

If I have a char data type this is represented with unicode consisting of
signed 16 bit integer.
If I have a reference datatype for example a string in this way
string test = "s";
then the location that test is refering is occupying 16 bits because of
Unicode representation.

I assume that this is correct understood of me ?

//Tony
 
T

Tony Johansson

Tony Johansson said:
Hi!

If I have a char data type this is represented with unicode consisting of
signed 16 bit integer.
If I have a reference datatype for example a string in this way
string test = "s";
then the location that test is refering is occupying 16 bits because of
Unicode representation.

I assume that this is correct understood of me ?

//Tony

No I changed my mind the location that test is refering to which is s must
be only one byte I assume

//Tony
 
T

Tom Shelton

No I changed my mind the location that test is refering to which is s must
be only one byte I assume

//Tony

Why would you assume that? char is a 16-bit value.
 
T

Tony Johansson

Tom Shelton said:
Why would you assume that? char is a 16-bit value.

As I mentioned a char data type this is represented with unicode consisting
of
a signed 16 bit integer.

If I have a reference datatype for example a string in this way
string test = "s";
then the location that test is refering to in this case s is occupying 16
bits because of
Unicode representation.

This must be correct because .NET encoding is based on Unicode ?

//Tony
 
T

Tom Shelton

As I mentioned a char data type this is represented with unicode consisting
of
a signed 16 bit integer.

If I have a reference datatype for example a string in this way
string test = "s";
then the location that test is refering to in this case s is occupying 16
bits because of
Unicode representation.

This must be correct because .NET encoding is based on Unicode ?

//Tony

Well,it's a little more complex then that... The s is occupying at least 16
bits of space - but, it can be more depending on the locale. Some languages
require 2 chars to represent 1 :)

Further you have the the object reference located in test - which will be 32
or 64 bits depending on the system ptr size. And then you have the actual
string object that lives at the referenced location, which has another
reference to the actuall location of the string data. If you think about it -
that's a lot of space just to store a single s :)
 
A

Arne Vajhøj

As I mentioned a char data type this is represented with unicode consisting
of
a signed 16 bit integer.

If I have a reference datatype for example a string in this way
string test = "s";
then the location that test is refering to in this case s is occupying 16
bits because of
Unicode representation.

This must be correct because .NET encoding is based on Unicode ?

The reference test is pointing to an object which consist
of a number of bytes, some with meta data telling that
this is a string, possibly a length field and the chars
that the string consist of in this case 1 char.

Arne
 
A

Arne Vajhøj

Well,it's a little more complex then that... The s is occupying at least 16
bits of space - but, it can be more depending on the locale.

It would certainly need to store some data besides the chars. Always.
Some languages
require 2 chars to represent 1 :)

No. All languages require 1 char to represent 1 char. Some languages
may have codepoints that require 2 chars to represent 1 codepoint.
Further you have the the object reference located in test - which will be 32
or 64 bits depending on the system ptr size. And then you have the actual
string object that lives at the referenced location, which has another
reference to the actuall location of the string data. If you think about it -
that's a lot of space just to store a single s :)

Yep.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top