Windows malloc replacement (e.g., tcmalloc) and dynamic crt linking

后端 未结 4 1097
既然无缘
既然无缘 2020-12-07 23:11

A C++ program that uses several DLLs and QT should be equipped with a malloc replacement (like tcmalloc) for performance problems that can be verified to be caused by Window

4条回答
  •  青春惊慌失措
    2020-12-07 23:48

    Q: A C++ program that is split accross several dlls should:

    A) replace malloc?

    B) ensure that allocation and de-allocation happens in the same dll module?

    A: The correct answer is B. A c++ application design that incorporates multiple DLLs SHOULD ensure that a mechanism exists to ensure that things that are allocated on the heap in one dll, are free'd by the same dll module.


    Why would you split a c++ program into several dlls anyway? By c++ program I mean that the objects and types you are dealing with are c++ templates, STL objects, classes etc. You CAN'T pass c++ objects accross dll boundries without either lot of very careful design and lots of compiler specific magic, or suffering from massive duplication of object code in the various dlls, and as a result an application that is extremely version sensitive. Any small change to a class definition will force a rebuild of all exe's and dll's, removing at least one of the major benefits of a dll approach to app development.

    Either stick to a straight C interface between app and dll's, suffer hell, or just compile the entire c++ app as one exe.

提交回复
热议问题