3 ms·
Manual deallocators are more interesting. PJSIP[1] has an interesting approach to this. SIP messages have lots of strings associated with them, are usually r
by efaref 11y ago
Manual deallocators are more interesting.
PJSIP[1] has an interesting approach to this. SIP messages have lots of strings associated with them, are usually relatively short-lived, and typically you'll want to modify these strings or attach new ones. PJSIP does this by hanging a string arena off of each SIP message object.
As you add strings to the SIP message, these get appended to the arena, which is grown automatically as and when it needs to be. If you delete a string, it just sticks around in the arena unused. Arena space can also be shared, e.g. if you copy a substring from one SIP header to another, it'll just be referred to twice using a pointer and length.
Finally, when you free the SIP message, it just frees the entire arena in one go.
[1] http://www.pjsip.org/ http://www.pjsip.org/
- PDoyle 11y agoYes, that kind of "transaction-based" memory management is beautiful in applications where it's appropriate: just leak memory until you're done with the current task, and free it in one chunk. That's hard to beat for performance and simplicity.