Makes a mess of the heap, need to reimplement with ptr_vectors or something c++ish