007 What are the rules for memory management?
- Status: accepted
- Deciders: partners
Memory ownership is never transfered between TEK and DC.
The interface partner which allocates memory is also responsible for freeing it.
Memory ownership must not be mixed in data structures
... otherwise it could not be freed safely.
The memory referenced by pointers which are passed to functions need not be valid longer than the function call.
As consequence it is not feasible to copy pointers only for later use. If data needs to be persisted for later use, a deep copy is neccessary. If ever any exception from this rule is needed it must be documented explicitely.
Memory passed to a function call is not modified from the caller while the function call is in progress.
That means the caller is responsible for thread safety of passed memory.
Memory passed to a function call is not modified from the callee, except it is explicitely allowed.
The interface uses the const qualifier to mark unmodifiable memory.
void pass_unmodifiable_memory(field_data const * data)