473,378 Members | 1,422 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,378 software developers and data experts.

String implementation ?

Hi,

how is a String implemented in .NET :

as in VB.NET : using a length-prefix located in front of the actual
characters
or
as in C : using '\0' (backslash null)

thnx
Chris
Nov 16 '05 #1
6 1599
Chris,

It probably uses a length-prefix somewhere. However, because the object
is managed, you won't be able to access it (except indirectly through the
Length property).

Also, since strings are immutable, if you modified this prefix, it could
have some very bad ramifications.

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

"Chris" <ch********@pandora.be> wrote in message
news:ru***********************@phobos.telenet-ops.be...
Hi,

how is a String implemented in .NET :

as in VB.NET : using a length-prefix located in front of the actual
characters
or
as in C : using '\0' (backslash null)

thnx
Chris

Nov 16 '05 #2
how is a String implemented in .NET :


They both contain a terminating null character and has the length
stored.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 16 '05 #3
"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:eN**************@TK2MSFTNGP09.phx.gbl...
how is a String implemented in .NET :


They both contain a terminating null character and has the length
stored.


I'm not sure that it does have a terminating NUL (*), however, even if
it does, it's irrelevant, as String allows internal NUL characters.
(*) "NUL" = a single character of value Zero.
"Null" = an pointer/reference value indicating it is unassigned.

--
Truth,
James Curran
Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com
(note new day job!)
Nov 16 '05 #4
James Curran <Ja*********@mvps.org> wrote:
"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:eN**************@TK2MSFTNGP09.phx.gbl...
how is a String implemented in .NET :
They both contain a terminating null character and has the length
stored.


I'm not sure that it does have a terminating NUL (*), however, even if
it does, it's irrelevant, as String allows internal NUL characters.


It's far from irrelevant - it's vital for interop. If strings weren't
nul/null-terminated, you wouldn't be able to pass them to native code
which expected them to be nul/null-terminated.
(*) "NUL" = a single character of value Zero.
I think it depends on where you're getting your terminology from. For
instance, looking at http://www.unicode.org/charts/PDF/U0000.pdf
the box in the character chart has "NUL" in it, but the description is
"NULL".
"Null" = an pointer/reference value indicating it is unassigned.


There's a difference between "unassigned" and "assigned a null
reference".

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #5
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...

It's far from irrelevant - it's vital for interop. If strings weren't
nul/null-terminated, you wouldn't be able to pass them to native code
which expected them to be nul/null-terminated.

By the time it's reached interop, it's already gone through marshalling,
where it could have added the nul-terminator (at the same time it removes
the length).

--
Truth,
James Curran
Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com
(note new day job!)
Nov 16 '05 #6
James Curran <Ja*********@mvps.org> wrote:
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
It's far from irrelevant - it's vital for interop. If strings weren't
nul/null-terminated, you wouldn't be able to pass them to native code
which expected them to be nul/null-terminated.


By the time it's reached interop, it's already gone through marshalling,
where it could have added the nul-terminator (at the same time it removes
the length).


Well, it can do that in cases where the marshalling is copying the
data. When it's not copying the data, the null already needs to be
there, surely - or there at least needs to be enough space for it. (I
don't believe the length is removed, so much as the pointer passed to
unmanaged code is the address of the first character of the string.)

Maybe I'm wrong and the contents is always copied though. It seems a
shame if this is the case - and I'm pretty sure that the null always
*is* there. The space taken up by the character data is always a
multiple of 4 bytes, and the way I've seen it expand suggests that
there's always at least *room* for the null.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #7

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

Similar topics

9
by: Mathieu Malaterre | last post by:
Hello, This thread follow my previous one on the gcc mailing list. Basically I -still- have a problem in my code. I define in a header file: static const std::string foo = "bar"; Which not...
14
by: brad | last post by:
I've got a multithreaded application using std::string in Linux. Performance is not very good so I ran Quantify(tm) to look at what is happening. Most of the time my app was calling...
37
by: jortizclaver | last post by:
Hi, I'm about to develop a new framework for my corporative applications and my first decision point is what kind of strings to use: std::string or classical C char*. Performance in my system...
53
by: Jeff | last post by:
In the function below, can size ever be 0 (zero)? char *clc_strdup(const char * CLC_RESTRICT s) { size_t size; char *p; clc_assert_not_null(clc_strdup, s); size = strlen(s) + 1;
8
by: vidya.bhagwath | last post by:
Hello Experts, I am using std::string object as a member variable in one of the my class. The same class member function operates on the std::string object and it appends some string to that...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.