All of lore.kernel.org
 help / color / mirror / Atom feed
From: Rusty Russell <rusty@rustcorp.com.au>
To: Stuart Longland <stuartl@longlandclan.id.au>, ccan@lists.ozlabs.org
Cc: Stuart Longland <me@vk4msl.id.au>
Subject: Re: [PATCH] btree: Add custom allocator interface.
Date: Mon, 08 Feb 2016 14:11:32 +1030	[thread overview]
Message-ID: <87egcnhnrn.fsf@rustcorp.com.au> (raw)
In-Reply-To: <56B7FF57.1010704@longlandclan.id.au>

Stuart Longland <stuartl@longlandclan.id.au> writes:
> On 08/02/16 10:45, Rusty Russell wrote:
>> stuartl@longlandclan.id.au writes:
>>> From: Stuart Longland <me@vk4msl.id.au>
>>>
>>> This provides a way for btree to be used with external allocator
>>> libraries such as the tal or talloc modules.
>> 
>> Sure.  In my libraries I generally use a global allocator override;
>> it's not thread-safe, but much easier to use in practice.
>> 
>> Since I don't use btree, I'm agnostic about it though!
>
> Indeed, actually I'm half considering whether we make it a separate
> module that `btree` (and others) can pull into their code.  There are
> lots of cases where `tal` or `talloc` is desirable over the standard C
> malloc/free.

Yes, I've been all over the place on this.  Opt has opt_set_alloc(),
(a global), rbuf takes an explicit realloc function, io just assumes
tal, tal/grab_file is actually a tal submodule (the old one is
deprecated, will be removed RSN).

There's a balance of "big enough that needing tal is not an issue",
"standalone enough that I want to avoid a dependency" and "API
simplicity".

>>> +struct btree *btree_new_with_alloc(btree_search_t search,
>>> +		const struct btree_allocator *alloc)
>>> +{
>>> +	struct btree *btree = (*(alloc->malloc))(alloc, sizeof(struct btree));
>> 
>> You can call a function pointer, so alloc->malloc(alloc, sizeof(struct btree));
>> should work.  
>
> Ahh, didn't know about that.  I presume a more recent C standard?  I'll
> admit I had to look up the syntax for function pointers off Wikipedia as
> I don't do it often enough.

It's one of those weirdnesses that has been around forever; pretty sure
it was in K&R but I don't have that on hand.

Cheers,
Rusty.
_______________________________________________
ccan mailing list
ccan@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/ccan

  reply	other threads:[~2016-02-08  3:43 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-07  0:10 [PATCH] btree: Add custom allocator interface stuartl
2016-02-08  0:45 ` Rusty Russell
2016-02-08  2:37   ` Stuart Longland
2016-02-08  3:41     ` Rusty Russell [this message]
2016-02-08  4:24       ` Stuart Longland
2016-02-08  2:17 ` David Gibson
2016-02-08  4:26   ` Stuart Longland
2016-02-08 23:40     ` David Gibson
2016-02-09  2:14       ` Stuart Longland

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87egcnhnrn.fsf@rustcorp.com.au \
    --to=rusty@rustcorp.com.au \
    --cc=ccan@lists.ozlabs.org \
    --cc=me@vk4msl.id.au \
    --cc=stuartl@longlandclan.id.au \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.