When dealing with very large strings, it is preferable to use realloc rather than malloc+copy+free every time, especially on Linux where realloc eventually becomes mremap(2). Unfortunately this requires changing the interface of obstack, but IMHO it needs to be done.