I have seen "malloc" as kind of replacement for "new" to create some heap memory and return a pointer to it (though I still wonder why would one need to use malloc instead of new), but I wonder what TBB "scalable_malloc" brings different from "malloc". And what situation it best fits to use "scalable_malloc" ?
The principal difference between malloc and new, or between scalable malloc and overloaded new with scalable new is the "new" methodcan include an object constructor (your code to be executed upon allocation). Similar with the return of memory using free and delete, or scalable_free and scalable delete (overloade delete) and its ability to have an object destructor (your code).
The principal differences between the non-scalable variants and the scalable variants are
non-scalable multi-threaded heap (malloc/new, free/delete) uses critical sections. whereas scalable methods reduce the frequency of entering critical sections. In some cases thereduction (ratio of with critical section to without critical section) aproacheszero.
malloc often has less overhead than new (although optimizing compilers may make this a moot point). The advantage for new/delete even for objects that do not require a constructor is the ability to use anencapsulation object which holds the POD (Plane Old Data) and then when the encaptulation object exits scope that your dtor can delete the encapsulated object. What this means is should a function using such an encapsulation object contain multiple exit points (returns), then you do not have to maintain multiple clean-up sections of code (a common place for error of omission). Note, the encapsulate object can use either malloc/new and free/delete.