I don't know why nobody pointed out the obvious solution yet. Just pass the output object by reference:
void f(Object& result) {
result.do_something();
result.fill_with_values(/* */);
};
This way:
you avoid the copy for sure.
you avoid using the heap.
you avoid leaving the calling code with the responsibility of freeing the dynamically-allocated object (although shared_ptr or unique_ptr would do that too).
Another alternative is to make the function a member of Object, but that might not be appropriate, depending on what f()'s contract is.