plugins and memory-management

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • plugins and memory-management

      I want to do a flexible pluginsystem, but I have problems with allocated memory from the plugin (also used by strings). Currently if a string (allocated from a plugin) isn't used anymore a plugin-function freeString is called, but that's very slow because I have to alloc new memory everytime I want to return a string from the plugin to the mainprogram. is there a more clever way to handle this situation?

      As I understand it I have to free the memory in the plugin again, because the plugin could use it's own c-runtime with own heap-management (besides the plugin could use malloc/free and the mainprogramm could use new/delete).

      how is this situation handled in other programs? is it a better option to use the dll-c-runtime and to specifiy to always use new/delete?
    • RE: plugins and memory-management

      By string, do you mean std::string? Either way, one solution might be to pass a pointer or reference to a string as an output parameter instead of returning a new string on the stack. For example:

      Source Code

      1. // this...
      2. void GetName(std::string& pOutputName);
      3. // not this....
      4. std::string GetName(void);


      Not sure if this is what you're looking for.

      -Rez