DLL memory manager mixup

后端 未结 3 1695
清歌不尽
清歌不尽 2020-12-21 13:09

I wrote an application which allows people to contribute plugins to extend the functionality. Such plugins are deployed as DLL files, which the framework picks up during run

3条回答
  •  攒了一身酷
    2020-12-21 13:34

    It turned out that the easiest way to make sure that memory is not allocated in one DLL and released in another is this: reimplement operator new and operator delete on the base class of the objects which are returned from the plugins. In the implementations of these functions, call 'alloc' and 'free' functions (which have been passed from the main application when loading the plugin). That way, plugins can keep using 'new' and 'delete' but the memory will actually be allocated and released in the main application.

提交回复
热议问题