Using tokens
Use the token mechanism to provide a constant string that can be shared. Tokens provide a useful mechanism for giving a persistent name to an object that is used by more than one program.
Some examples of ways you might use tokens within the system are:
- Providing identifiers for permanent system resources, such as constant identifiers for particular fonts or text styles, or constant names for localizable objects
- Passing strings between programs, for example, in an IPC message
- Internal string handling, such as streaming or fast, language-insensitive comparisons
When you instantiate TToken, the system creates a permanent memory location to store the text string. This mechanism makes referencing tokens much faster than referencing text instances. Because this mechanism uses shared storage, however, do not use tokens when they are unnecessary. Each token you create takes up a piece of shared memory that is not freed until you reboot your system.
You can create a token by specifying a character string as either:
- A UniChar array
- A TText instance
For tokens you will use often, you might want to create them as static constants, for example:
static TToken chicagoFont( "Chicago" );
TToken defines an invalid token as a token containing no character data. The system does not assign an identifier to an empty token. TToken throws an exception--TTokenException--if you try to use an invalid token.
TIP
Do not derive classes from TToken. It is intended for use as a primitive data type and should only be instantiated.
[Contents]
[Previous]
[Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.
Generated with WebMaker