From: Junio C Hamano Date: Thu, 06 Oct 2016 22:53:35 GMT Subject: Re: [PATCH v2 05/25] sequencer: allow the sequencer to take custody of malloc()ed data Message-ID: In-Reply-To: <28935e27-5ba8-c261-ba44-424f7b91cdda@gmail.com> Jakub Narębski writes: >> 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.