DefaultXmlNameTable Class
Namespace: System.Xml
Assembly: System.Xml.dll
Summary
Represents the default implementation of the XmlNameTable class. The default name table uses a hash table to store atomized string objects and provides fast retrieval of these strings.
Syntax
public sealed class DefaultXmlNameTable : XmlNameTable
{
public DefaultXmlNameTable();
public override string Add(string str);
public override string Get(string str);
public override string Get(char[] key, int startIndex, int length);
}
Remarks
The DefaultXmlNameTable
class is optimized for read‑heavy scenarios where many duplicate strings are processed. String atomization reduces memory usage and improves comparison performance because identical strings share the same reference.
- The
Add
method inserts a new string into the table if it does not already exist and returns the atomized reference. - The
Get
overloads retrieve an existing atomized string without allocating a new string object. - The implementation is thread‑safe for read operations; however, writes (i.e., calls to
Add
) should be synchronized if used across multiple threads.
Example
using System;
using System.Xml;
class Program
{
static void Main()
{
XmlNameTable nameTable = new DefaultXmlNameTable();
string s1 = nameTable.Add("example");
string s2 = nameTable.Get("example");
Console.WriteLine(Object.ReferenceEquals(s1, s2)); // True
}
}
Properties
Member | Description |
---|---|
Add(string str) | Atomizes and adds a string to the table. |
Get(string str) | Retrieves an atomized string if it exists. |
Get(char[] key, int startIndex, int length) | Retrieves an atomized string from a character array slice. |