Marshallers

Db4o marshaller implementation uses reflection to detect class fields.  This approach is universal, but reflection usage imposes a certain performance penalty. In some cases you may want to improve the performance using custom marshallers through a plug-in interface:

c#: 

Db4oFactory.Configure().ObjectClass(typeof(YourClass)).MarshallWith(yourMarshaller);

VB: 

Db4oFactory.Configure().ObjectClass(GetType(YourClass)).MarshallWith(yourMarshaller)

Custom marshaller provides a functionality to convert object fields to a byte array and back. This approach allows to achieve a better performance due to the following:

  • reflection is not used to detect object fields;
  • only the required fields need to be marshalled.

However there are certain limitations:

  • custom marshaller is not compatible with the use of a translator;
  • quering for fields is not possible when a custom marshaller is used. 

Custom marshallers should implement an ObjectMarshaller interface:

c#: 

public class CustomMarshaller: IObjectMarshaller

VB: 

Class CustomMarshaller

Implements IObjectMarshaller

To simplify the task of creating custom marshallers db4o provides a PrimitiveCodec class, which implements write and read functions for int and long values.