The difference between space requirement of NULL string and EMPTY string

The Common Language Infrastructure Specification (6th Edition / June 2012), describes how string is physically stored as follows:

 

image

If the parameter kind is string, (middle line in above diagram) then the blob contains a SerString – a PackedLen count of bytes, followed by the UTF8 characters. If the string is null, its PackedLen has the value 0xFF (with no following characters). If the string is empty (“”), then PackedLen has the value 0x00 (with no following characters). (Page 294)

So, by definition, it can be concluded that null string occupies exactly the same space as empty string. 

As another case, this blog post compares the size of two tables in SQL Server with full of nulls and empty strings relatively. It proves that null string and empty string requires exactly the same size on disk. 

In conclusion, it is likely that both CLI and SQL Server implements the same logic to store string physically.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s