#Quick question: Will pointer capture be better here or not and why?

1 messages · Page 1 of 1 (latest)

odd dune
#
        if (self.particles) |p| {
            p.deinit(allocator);
            self.particles = null;
        }

// OR

        if (self.particles) |*p| {
            p.deinit(allocator);
            p.* = null;
        }

#

ping me please, thx!

slate finch
#

depends what self.particles and .deinit is

#

if its an ?ArrayList or similar, value copy might not work

#

capturing without a pointer makes a const copy, but usually deinit functions require mutable pointers

silent silo
#

@odd dune preety sure the second one would not compile youd still have to do self.particles = null instead of p = null, and what Matthis said ^

odd dune
slate finch
#

2nd one would work with p.* = null

#

need dereference operator to write

odd dune
#

yeah i meant that, my bad

#

alright, using the 2nd one 👍