Posted April 23, 2016
![avatar](http://images.gog.com/efc780a273eff0c808dc7692ed2049e0f456a167af84e40426480e9bd6edceea_avm.jpg)
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 );
![avatar](http://images.gog.com/3b007c3bba753fb4b1f2e418ece1a216fb18b0b1deb9d4d988b0cbae7a54f6ab_avm.jpg)
(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.