如何在c ++模式下gsoap释放内存工作?

时间:2013-08-02 13:01:03

标签: c++ gsoap

我使用gsoap为我的Web服务生成一些类,在我的类的破坏中我没有看到任何免费或删除语句,我必须删除类manualy的成员吗? - 或者gsoup destroy函数有责任吗? 这是我的样本之一:

class SOAP_CMAC ns2__FirstOfflineReserve
{
public:
    short *consumed;    /* optional element of type xsd:short */
    class ns2__FirstOfflineFood *food;  /* optional element of type ns2:FirstOfflineFood */
    class ns2__FirstOfflineFoodType *foodType;  /* optional element of type ns2:FirstOfflineFoodType */
    int *id;    /* optional element of type xsd:int */
    class ns2__FirstOfflineMeal *meal;  /* optional element of type ns2:FirstOfflineMeal */
    short *remainCount; /* optional element of type xsd:short */
    short *selectedCount;   /* optional element of type xsd:short */
    std::string *serialCard;    /* optional element of type xsd:string */
    std::string *username;  /* optional element of type xsd:string */
    struct soap *soap;  /* transient */
public:
    virtual int soap_type() const { return 36; } /* = unique id SOAP_TYPE_ns2__FirstOfflineReserve */
    virtual void soap_default(struct soap*);
    virtual void soap_serialize(struct soap*) const;
    virtual int soap_put(struct soap*, const char*, const char*) const;
    virtual int soap_out(struct soap*, const char*, int, const char*) const;
    virtual void *soap_get(struct soap*, const char*, const char*);
    virtual void *soap_in(struct soap*, const char*, const char*);
             ns2__FirstOfflineReserve() { ns2__FirstOfflineReserve::soap_default(NULL); }
    virtual ~ns2__FirstOfflineReserve() { }
};

我看到了保存活动肥皂的教程,以便更快地调用webservice,就像这个例子一样

calcProxy calc(SOAP_IO_KEEPALIVE); // keep-alive improves connection performance
   double sum = 0.0;
   double val[] = 5.0, 3.5, 7.1, 1.2 ;
   for (int i = 0; i < 4; i++)
      if (calc.add(sum, val[i], sum))
         return calc.error;
   std::cout << "Sum = " << sum << std::endl;
   return 0;

现在我们不调用soap的破坏功能,所以我不需要担心删除soap对象?

1 个答案:

答案 0 :(得分:1)

我已经使用gsoap生成的文件作为.dll项目的组件,在.dll条目部分我使用了以下内容:

int __stdcall DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
    switch (fdwReason)
    {
        case DLL_PROCESS_ATTACH:  

            /* create a soap environment (provides soap services) */
            soap = soap_new();  

            break;
        case DLL_PROCESS_DETACH:  

        /* terminate soap services */
        soap_end(soap);  //discontinue soap services
        soap_free(soap);  //free soap resources  

        break;
    }

    /* Return 1 to indicate successful initialization */
    return 1;
}

这种方法不会导致内存泄漏。您可以在c ++代码中使用这样的改编,不是吗?