473,788 Members | 2,814 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

c# string size limit? length of string limit?

c# string size limit? length of string limit?
Apr 19 '06 #1
5 5440
"Daniel" <so************ *******@yahoo.c om> wrote in message
news:Or******** ******@TK2MSFTN GP05.phx.gbl...
c# string size limit? length of string limit?
Limit of available contiguous free memory block or 2^31 chrs.

Apr 19 '06 #2
Michael C <no****@nospam. com> wrote:
"Daniel" <so************ *******@yahoo.c om> wrote in message
news:Or******** ******@TK2MSFTN GP05.phx.gbl...
c# string size limit? length of string limit?


Limit of available contiguous free memory block or 2^31 chrs.


Not quite - I believe the top bits of the length are taken for extra
flags, and there's always an extra null terminator, so it's 2^30-1
chars. Not that I expect it'll make a difference to anyone :)

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Apr 19 '06 #3
"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Not quite - I believe the top bits of the length are taken for extra
flags, and there's always an extra null terminator, so it's 2^30-1
chars. Not that I expect it'll make a difference to anyone :)
Does C# use a null chr?

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Apr 19 '06 #4
Michael C wrote:
"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Not quite - I believe the top bits of the length are taken for extra
flags, and there's always an extra null terminator, so it's 2^30-1
chars. Not that I expect it'll make a difference to anyone :)


Does C# use a null chr?


C# itself doesn't need it - nor does most managed code, I believe.
(Unsafe managed code may use it for convenience, if it's sure there are
no null chars genuinely in the string.)

However, for interop reasons it's really handy to have the null char at
the end anyway - a pointer can be passed to any unmanaged code which
expects a null-terminated UTF-16-encoded string, without copying
anything.

Jon

Apr 19 '06 #5

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
| Michael C <no****@nospam. com> wrote:
| > "Daniel" <so************ *******@yahoo.c om> wrote in message
| > news:Or******** ******@TK2MSFTN GP05.phx.gbl...
| > > c# string size limit? length of string limit?
| >
| > Limit of available contiguous free memory block or 2^31 chrs.
|
| Not quite - I believe the top bits of the length are taken for extra
| flags, and there's always an extra null terminator, so it's 2^30-1
| chars. Not that I expect it'll make a difference to anyone :)
|
| --
| Jon Skeet - <sk***@pobox.co m>
| http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
| If replying to the group, please do not mail me too

The CLR (currently) limits the size of an object to 2^31 bytes. That means
that the string buffer size is limited to (2^31 - size of the object header)
bytes, or 2^31-16 bytes or 2^30-8 = 1073741816 characters in .NET.

There is only a trailing null terminator if the buffer is large enough, in
the maximum case there isn't a null terminator.
Note that such string cannot be created on Windows 32 bit.

Willy.
Apr 19 '06 #6

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

Similar topics

8
4730
by: Hal Vaughan | last post by:
Is there a maximum length for Javascript program lines? What about strings? Is there a limit on string length? I found some references that said the maximum string length was 256 characters, but I have a program that created a string of over 25,000 characters (the browser was Konqueror). Are there limits on these lengths? If I require a newer browser for the program I'm writing, would that change the situation?
15
2027
by: Andrew Brampton | last post by:
Hi, I'm new to using std classes, but I was wondering how I could do the following efficiently with the string class: Say I had a string with delimited values such as: "field1,field2,field3,field4" and I wanted to to place those 4 fields into different variables I would do something like: /* Note code quickly pulled from my head - may be wrong :) */
2
12423
by: SJM | last post by:
In some VBA code I am building an SQL string to append a new record to a table. The string involves 40 fields. What I am finding is that it works with 39 fields but when I add 40 it fails with the error 3134 (syntax error). I am 99% sure there is no syntax error, rather I suspect that it could be due to limit on string length or number of fields. I have not been able to find anything that defines this though.
9
9160
by: Peter Row | last post by:
Hi, I know this has been asked before, but reading the threads it is still not entirely clear. Deciding which .Replace( ) to use when. Typically if I create a string in a loop I always use a StringBuilder. At present I am porting a VB6 webclass app to VB.NET and therefore I am trying to make it as efficent as possible via the new functionality of VB.NET.
5
2478
by: Sehboo | last post by:
Hi, Is there any easy way to limit the size of the string? I have Private msDescription As String I want to limit the msDescription to 50 instead of unlimitted.
53
4095
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;
2
22278
by: Daniel | last post by:
c# string size limit? length of string limit?
3
7420
by: ipellew | last post by:
Hi; Whats the maximum string length in Javascript. Is it the same across all the browsers? max_s_len = str.length // what the max number of chars we can have is str? Regards
158
6176
by: jty0734 | last post by:
i don't know what input size of string is. so i can't gets inputsize before malloc function. i want determine the size of malloc without get inputsize in advance. how to deal with it?
0
9656
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10366
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10173
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8993
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7517
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5399
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3674
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.