You are here: Configuration > Common Configuration > String Encoding

String Encoding

When db4o stores and loads strings it has to convert them to and from byte arrays. By default db4o provides three types of string encoding, which do this job: Unicode, UTF-8 and ISO 8859-1, Unicode being the default one. In general Unicode can represent any character set. However, it also imposes a certain overhead, as character values are stored in 4 bytes (less generic encoding usually use 2 or even 1 byte per character). In order to save on the database file size, it is recommended to use UTF-8, which only required one byte per character.

Note that the string encoding need to be the same on the server and clients. Also you cannot change the string encoding for an existing database. If you want to change the encoding, you need to defragment the database.

IEmbeddedConfiguration configuration = Db4oEmbedded.NewConfiguration();
configuration.Common.StringEncoding = StringEncodings.Utf8();
CommonConfigurationExamples.cs: Use the utf8 encoding
Dim configuration As IEmbeddedConfiguration = Db4oEmbedded.NewConfiguration()
configuration.Common.StringEncoding = StringEncodings.Utf8()
CommonConfigurationExamples.vb: Use the utf8 encoding

Of course you can also implement your own string encoding. You just need to implement the string encoding interface and pass it to this configuration.