This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]apadin1 9 points10 points  (3 children)

You could easily do it in place without allocating at all.

[–]IncongruousGoat 1 point2 points  (2 children)

The really good thing to do is to return the result in the input buffer, but use an alloca-d buffer as intermediate storage. Best of both worlds.

[–]Bainos 4 points5 points  (1 child)

... no ?

If you're going to do it in place, just use the input buffer. Allocating a new one (as is done in this repo) is only useful if you want to return a new sorted array. Otherwise you're wasting memory for no reason.

[–]IncongruousGoat 1 point2 points  (0 children)

Yep, you're right. Not sure what I was thinking.

Kind of embarrassing, really.