Platforms and compilers
For what platforms is OFC targetted?
At the moment the platforms Linux, Ubuntu, FreeBSD and WIN32 are targetted.
With which compilers is OFC tested?
There are not a lot of Objective-C compilers around. OFC is tested on the
Linux, Ubuntu and FreeBSD platform with the gcc compiler with Objective-C support. On
the WIN32 platform MingW32 is used. OFC is not tested with CYGWIN.
Class structure
Does OFC use a base object
Yes, OFC uses the standard class Object as base object. OFC doesn't introduce
an extra or another base class.
Memory management
Does OFC use reference counting?
No, OFC does not use reference counting. It introduces extra overhead and it will
not always work correctly.
Can I use a garbage collector with OFC?
Well I didn't try it, but I can't see a reason why it shouldn't work.
How does the collections handle objects?
Collections store pointers to objects. They will not make copies before they store
the objects. It is the decision of the programmer to make the collection the owner of
the object or some other object. To support the programmer there are two 'free' methods
in the collections:
- shallowFree
this method will only free the collection, not the
objects stored in the collection.
- free
this method will both free the collection and the objects
stored in the collection.
How do the DAvlTree and DHashTable store keys?
DAvlTree and DHashTable copy the key before storing, to prevent that
the key is changed outside the scope of the tree c.q. hashtable. As a result the key is
always freed when the tree c.q. hashtable element is freed.
How do I copy objects?
The standard class Object implements four methods for coping objects:
- shallowCopy
Default this method makes a binary copy of the original object. This is okee
for objects that only use basic data types (like int, long and so on) as
members, but not for objects that have private objects and dynamic variables
as members. In that case the shallowCopy method should be overridden
to make copies of these dynamic variables.
If an object stores external objects, as do collections, this method will not
copy the stored external objects, but keeps the reference to the object.
If an object is a copy made by shallowCopy method and there is a
shallowFree method, than the object must be freed by the
shallowFree method.
Keep in mind that the self pointer in this method is the pointer to the original
object. The copy is created by calling [super shallowCopy].
- copy
This method calls first the shallowCopy method and than the
deepen method. The shallowCopy will copy the object,
but will keep the references to external stored objects. The deepen
method will also copy the external stored objects. As a result the whole
object is copied, ala a deep copy.
If an object copy is made by the copy or deepCopy method and
there is a shallowFree method, the resulting object must be freed
by the free method.
- deepCopy
This method is identical to the copy method: it does a deep copy
of the object by calling shallowCopy and deepen.
- deepen
This method 'deepens' an already copied object. It calls the copy
method of all externally stored objects. As a result this method is normally only
implemented by collection classes.
Keep in mind that the self pointer in this method, points to the copied object.
Not all classes in the OFC library implements the
shallowCopy method.
If an object cannot be copied, a warning will be issued.
In the versions prior 0.7.1 the use of
shallowCopy results in an
object that shares private objects and dynamic variables with the original
object. As a result freeing the original or the copied object could result
in a seg-fault. In version 0.7.1 this is fixed.
Wrapper classes
Why is the wrapper class sometimes not named the same as the (external) library?
The name of the class is independant of the name of the external
library to make it possible to change the external library. For every
library it is possible that the development is discontinued or that there
will be a beter alternative one day. By using a more general name for the
wrapper class, there is a good chance that the underlying library can be
changed, without consequences for the interface of the wrapper class.
Is it possible to check if a wrapper class is present?
Classes that depend on other (external) libraries, will set a define to
indicate that the class is present in the OFC library. For example the class
DRegEx defines HAVE_DREGEX if the class is present.
Error handling
What type of errors are identified by OFC?
There are three types of errors identified by OFC:
- Runtime errors related to Objective-C
Examples: Method not implemented by a class, Out of memory.
- Programmer's errors
Examples: Index out of range, invalid value for a method parameter.
- Environment errors
Examples: File not found, connection unexpectedly closed.
How does OFC handle runtime errors?
OFC does not handle runtime errors. It is up to the programmer to set an error handler
(using objc_error_handler) and handle the errors.
How does OFC handle programmer's errors?
OFC uses the concept of Garbage in, defined value out. So for example if the programmer
uses an index that is out of range for an object, a warning is given and a valid (but possible incorrect)
value is returned. There are a few exceptions: test methods will return the
correctness of the parameter and will not give a warning, some parameters can not be checked
(for example an invalid pointer) and only parameters of OFC methods will be checked.
How does OFC handle environment errors?
Methods in OFC handle environment errors by returning a boolean that indicates success (or failure) or
returning an error code. The error code is comparable to the standard errno.
Some classes also implement test methods and methods to get more information about the error.
Does OFC use exceptions?
In the current version OFC does not use exceptions.