Click here to Skip to main content
15,894,343 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
StringBuilder consumes less memory than String ?
Posted

Since you failed to provide any context information about how you came to this conclusion, all we can say is "No, it does't". A string is a data structure that has a small amount of header information and array of bytes (usually 2 bytes per character) that hold the data for the string.

A StringBuilder holds an array of characters and has a bunch of code associated with it, so, in general, a StringBuilder cannot take up less memory than a string.

Oh! When you actually convert the StringBuilkder to a string so you can use it as such, it takes up about TWICE the memory of the target string. Once to hold the string instance and another to hold the StringBuilder and its data.
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900