Stream: t-libs/wg-allocators

Topic: &mut self


Mike Hommey (May 07 2019 at 07:45, on Zulip):

I'm starting to wonder what good &mut self on all the Alloc method does. Especially when it's renamed to AllocHandle, what does it mean to use a mutable reference to a handle?

Simon Sapin (May 07 2019 at 07:47, on Zulip):

I also have a hard time coming up with a scenario where &self wouldn’t work or make things harder. OTOH, are there cases where it would make things easier?

Mike Hommey (May 07 2019 at 07:55, on Zulip):

I wouldn't have to get a mutable ref in the code I'm writing right now.

Simon Sapin (May 07 2019 at 08:33, on Zulip):

Can you share that code? I’m curious in what kind of situation it makes a difference

Mike Hommey (May 07 2019 at 08:35, on Zulip):

Essentially my handle is an integer, and it's used to call into the moz_arena_* functions in mozjemalloc.

Mike Hommey (May 07 2019 at 08:36, on Zulip):

and I have a global for the id of the default arena

Mike Hommey (May 07 2019 at 08:44, on Zulip):

So the thing, really, is that Alloc with &mut self makes sense for the implementation of the allocator itself. And AllocHandle with &self for the handle.

Mike Hommey (May 07 2019 at 08:44, on Zulip):

where, in fact, for the handle type, we don't really need everything... we only need something that gets us a &mut Alloc

Mike Hommey (May 07 2019 at 08:45, on Zulip):

which circles back to the AllocFrom idea

Mike Hommey (May 07 2019 at 08:45, on Zulip):

(kinda)

Last update: Nov 15 2019 at 09:45UTC