WSReleaseInterfaceFromLinkServer (C 函数)

void WSReleaseInterfaceFromLinkServer(WSLinkServer s, const char *i)

释放在为服务器 s 调用 WSInterfaceFromLinkServer() 时,由 WSTP 库释放的内存 i.

更多信息

  • WSInterfaceFromLinkServer() 分配内存,以返回包含用于链接服务器连接的界面 IP 地址的 C 类型字符串. 一旦程序完成任务,该内存必须释放回 WSTP 库,这样库就可以回收这些内存.
  • 界面字符串 i,必须是由 WSInterfaceFromLinkServer()返回的 C 类型字符串指针.
  • 程序不应调用释放用 i 表示的字符串.

范例

基本范例  (1)

#include <stdlib.h> /* For malloc, free */
#include <string.h> /* For memset,memcpy */
#include "wstp.h"

void getInterfaceForLinkServer(WSLinkServer server)
{
    char *buffer;
    size_t length;
    const char *interface;
    int error;

    interface = WSInterfaceFromLinkServer(server, &error);
    if(interfaced == (const char *)0 || error != WSEOK)
    { /* Handle error */ }

    length = strlen(interface);

    buffer = (char *)malloc((length + 1) * sizeof(char));
    if(buffer == (char *)0)
    { /* Handle out of memory condition */ }

    memset((void *)buffer, 0, (length + 1) * sizeof(char));

    memcpy((void *)buffer, (void *)interface, length * sizeof(char));

    WSReleaseInterfaceFromLinkServer(server, interface);

    /* .. do something with buffer... */

    free(buffer);

    return;
}