On 11 May 2007, at 19:07, Lionel MARTIN wrote:
-another example hat comes to my mind is a project (implemented in PHP) where I had to work. Part of the process was retrieving cached HTML template pages from the server and do BB tags parsing before serving the client. Of course, you would tell me that I could retrieve the data chunk by chunk, but this is not as obvious, as some BB tags could spread over several lines. So, this would need to devise an algorithm to be sure we are not cutting in the middle of a tag. In this kind of situation and if the file to be retrieved don't grow too large, I would prefer to retrieve the file all at once, do the processing, serve it to the client, and then, undef the buffer. Far easier than doing chunk by chunk.

Same thing: you'd presumably wrap that data in an object.

OK.

Basically, I would an object here, containing why not a scalar member.
This way, when the reference to the object goes out of scope, the memory associated to the object would go out of scope as well. Finally, that's a devious way of doing what I was suggesting at the beginning: use a lexical variable and undef it.

Wrapping that in an object would make trhe whole lot automatic (if I'm not mistaking).

Yup, that's it. Basically as soon as there's at least one reference (either an object handle or just a ref to a hash, scalar or array) between the scalar and the bulk of the data that memory will be freed when all the references to it go away.

--
Andy Armstrong, hexten.net

Reply via email to