Posted April 23, 2016

the memory for "buffer" is allocated via new. it is not occupying stack memory, but heap memory. Returning it would be totally fine in C/C++.
the C equivalent would be:
char *buffer = malloc( num_bytes );

(Putting free() inside the function won't work for a reason that should be obvious.)
On a similar vein, it's like the old COM days when you had to know when to call AddRef() vs. Release().
I think one of the still outstanding gripes about C++ (aside from its increasingly annoying syntactical changes) is its lack of a garbage collection facility.
To this day, I've never found anything better than Assembly language when it comes to communicating with a machine; however, adding a higher level language like C makes it easier to do logical and repetitive constructs.