in reply to Not returning scalars(SV) to optimize and save memory?
For the second subroutine, you use memory when you return. I would argue that you create a result value (in this case a boolean, although Perl doesn't use booleans explicitly). Whatever that value is, it takes up memory space to store the result of your comparison. You may think that by defining the values above you save memory but you don't. You return a copy of that value. Even assuming return uses references (which I'd say is not the case) you'd still be using memory to store the reference to the value defined up top. Your bar return does more than flow of control, it actually passes a value up to the parent.
For this reason, I think the claim that Perl does not use additional resources to represent that value internally is incorrect. It is a bool after all (Perl chooses not to call it so) but it is a value and that takes up space. If you optimize it to save that space it pretty much means you destroy what yo want to return. It seems you'd be looking for a meaningful value but are willing to spend zero to store it.
Again, my 2c without knowing intimate details about how Perl handles the situation, but based on this line of thinking, I suspect there's little room for other scenarios. Anybody has any other idea?
|
|---|