Leopold Toetsch wrote:
Brent Dax wrote:
Can we add a way to explicitly free the memory associated with a buffer without freeing the header? That seems like it could be useful in other areas too (although I'm not quite sure where)
.... did I write - but - there is always a but - I tried something similar:So mixing the 2 schemes is a PITA, IMHO.
I changed:
inline op substr(out STR, in STR, in INT, in INT) {
STRING **s = &$1;
if (*s && *s != $2 && !((*s)->flags & BUFFER_bufstart_external_FLAG))
add_free_buffer(interpreter,
(*s)->flags & BUFFER_constant_FLAG ?
interpreter->arena_base->constant_string_header_pool :
interpreter->arena_base->string_header_pool,
*s);
*s = string_substr(interpreter, $2, $3, $4, s);
}
This gives +25 % performance in life.pasm (where substr is the one function doing 10^6 new strings).
This doesn't reuse existing string headers, but by returning the string to the memory system, whenever a new one is generated in string_substr, DOD runs are going down from ~40000 to ~10. Reusing the header too, would give another some % improvement.
Above inserted code could of course be hidden in some function or in substr (and similar functions, taking a destination string) itself.
This could be done for all (which aren't too much) OPs wher a SReg or PReg is globbered.
leo