In message <[EMAIL PROTECTED]>
          Nicholas Clark <[EMAIL PROTECTED]> wrote:

> On Wed, Jan 29, 2003 at 02:25:50PM +0000, Miah Gregory wrote:

> These two will *copy* the data from aptr and bpr to the two variables,
> not "steal" the pointers. As the savepv/savepvn have just made malloc()ed
> copies, and setpvn() doesn't take the pointer from you, so each time round
> you've got 2 more malloc()ed bits of data that aren't free()d.

Ah.. Strange. I did try it the way you're suggesting before, but I was
receiving segfaults, so I presumed that I needed to copy it first. Having
retried without the copy, it works. Very odd.

Having said that, I accidentally missed a */ to close a comment, and got
segfaults from that too, yet no compilation failure, which was strange.

> replace the if clause with
-snip-
> and I believe that it will all work as before, but no leaks.

Yeah, that works perfectly. Thanks for pointing out the mistake.

> > Sort of unrelated, I notice that there are a lot of functions with names
> > like xxx_mg, whose descriptions talk about handling 'set' magic. What
> > does this mean?

> I'd suggest reading perlguts, which describes itself as "Introduction to
> the Perl API" for more general information.

Ah, great.. I've looked through a few more of the listed pod manuals now,
so I'm feeling a little surer about what I'm doing.

> I don't know if it's covered there coherently, but you'd need to worry
> about set magic if you were setting the values on SVs passed in to you. The
> new SVs you've just created don't have any magic, so you aren't going wrong
> by "not handling 'set' magic"

> "magic" implements all sorts of special behaviour by allowing SVs to have
> routines attached that are called when their value is got, set, cleared,
> etc. "not handling magic" means that a routine doesn't look to see if there
> is any "magic" attached, and therefore doesn't do the correct thing -
> calling any magic routines, as a consequence of not even looking.

Right, that makes sense. Thanks for explaining it.

Anyhow, my routine is now working, and it seems to save a /lot/ of memory
when dealing with large scalars, which is great. I'm still seeing a great
deal of memory being swallowed up, but this seems to shave off 30/40%.

Many thanks everyone. :-)

-- 
Miah Gregory

Reply via email to