[fpc-devel] strings: a proposeal

peter green plugwash at P10Link.net
Sun Feb 4 01:01:29 CET 2007


currently there is some demand for a fast widestring type on windows and i suspect there will be requirements for more string types in the future.

So i make a proposal for a new syntax that will allow string types to be created easilly in libraries or user code.

my proposal is a statement like

type
  tmystring=string(elementtype,allocator,deallocator,copier,uniquer);

the allocator,deallocator,copier and uniquer would generally be inline functions

the elementtype may be any type that doesn't use any compiler magic
the allocator allocates a new string of a given number of elements and returns a pointer to the first element, length refcount

the allocator and deallocators jobs are obvious to create new strings and reduce the reference count of/dispose of old ones.

the copiers job is to increase the reference count if the string is reference counted or copy the string if not

the uniquers job is to copy the contents of the string if it is refcounted and its reference count is greater than 1.

indexing of the string would be handled in the same way as current strings, that is normally direct access but call the uniquer automatically before starting writes

if my understanding is correct this should allow all the widestrings stuff to be moved to the library and people to implement thier own string types as required (for example maybe a widestring counterpart for some system that is similar to com)




More information about the fpc-devel mailing list