One embodiment of the present invention provides a system for implementing
a string object defined in a programming language. Upon receiving
characters to be embedded in the string object, the system allocates
space for the string object that includes a header, which is appended to
a character array of the string object. Next, the system copies the
characters into the character array of the string object. The system also
initializes the header by initializing a class pointer in the header to
point to a class for the string object, and by initializing a length
field in the header to specify a length for the string object. In this
way, the string object remains compatible with previous implementations
of the string object that use a character array that is separate from the
string object.