Thread (1 message) 1 message, 1 author, 2016-10-06

Re: [PATCH v2 05/25] sequencer: allow the sequencer to take custody of malloc()ed data

From: Junio C Hamano <hidden>
Date: 2016-10-06 22:53:43

Jakub Narębski [off-list ref] writes:
quoted
We manage lifetime of a field in a structure in one of three ways in
our codebase [*1*].

 ...
 * A field can sometimes own and sometimes borrow the memory, and it
   is accompanied by another field to tell which case it is, so that
   cleaning-up can tell when it needs to be free(3)d.  This is a
   minority case, and we generally avoid it especially in modern
   code for small allocation, as it makes the lifetime rule more
   complex than it is worth.
...
On the other hand the _entrust() mechanism might be a good solution
if the amount of memory was large, for example order of magnitude more
than what would be needed to keep ownership info *and* borrowing would
not be possible for some reason.
We have approach #3 exactly for that usage pattern.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help