Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Multithreading er的解决方案是完全摆脱共享状态。您可以通过在setClue中分配一个SRCH_结构并返回该指针来实现这一点。然后,对srchString的每次调用都会将该SRCH_STRUCT指针作为参数。VB.Net代码只需将此结构视为IntPtr中的结构,它不需要知_Multithreading_Sql Server 2008_Clr_User Defined Functions_Unmanaged - Fatal编程技术网

Multithreading er的解决方案是完全摆脱共享状态。您可以通过在setClue中分配一个SRCH_结构并返回该指针来实现这一点。然后,对srchString的每次调用都会将该SRCH_STRUCT指针作为参数。VB.Net代码只需将此结构视为IntPtr中的结构,它不需要知

Multithreading er的解决方案是完全摆脱共享状态。您可以通过在setClue中分配一个SRCH_结构并返回该指针来实现这一点。然后,对srchString的每次调用都会将该SRCH_STRUCT指针作为参数。VB.Net代码只需将此结构视为IntPtr中的结构,它不需要知,multithreading,sql-server-2008,clr,user-defined-functions,unmanaged,Multithreading,Sql Server 2008,Clr,User Defined Functions,Unmanaged,er的解决方案是完全摆脱共享状态。您可以通过在setClue中分配一个SRCH_结构并返回该指针来实现这一点。然后,对srchString的每次调用都会将该SRCH_STRUCT指针作为参数。VB.Net代码只需将此结构视为IntPtr中的结构,它不需要知道任何关于SRCH_结构的定义。注意:您还需要向DLL中添加一个新函数,以取消分配分配的SRCH_STRUCTshf301我希望知道如何给您评分或将问题标记为已回答。你给出的答案解决了眼前的问题。非常感谢。我还决定尝试将模糊代码转换为c#,以避


er的解决方案是完全摆脱共享状态。您可以通过在
setClue
中分配一个
SRCH_结构
并返回该指针来实现这一点。然后,对
srchString
的每次调用都会将该
SRCH_STRUCT
指针作为参数。VB.Net代码只需将此结构视为IntPtr中的结构,它不需要知道任何关于
SRCH_结构的定义。注意:您还需要向DLL中添加一个新函数,以取消分配分配的
SRCH_STRUCT

shf301我希望知道如何给您评分或将问题标记为已回答。你给出的答案解决了眼前的问题。非常感谢。我还决定尝试将模糊代码转换为c#,以避免从托管VB跳到c DLL所带来的巨大性能损失。尽管如此,谢谢你的帮助,伙计!
SELECT Field FROM Table WHERE xudf_fuzzy('doppler effect', Field) = 1;
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.SqlTypes
Imports System.Text
Imports Microsoft.SqlServer.Server
Imports System.Runtime.InteropServices


Partial Public Class fuzzy

<DllImport("C:\Users\Administrator\Desktop\fuzzy64.dll", _
           CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function setClue(ByRef clue As String, ByVal misses As Integer) As       Integer
End Function

<DllImport("C:\Users\Administrator\Desktop\fuzzy64.dll", _
           CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function srchString(ByRef text1 As String) As Integer
End Function


<Microsoft.SqlServer.Server.SqlFunction()> Public Shared Function _
        xudf_fuzzy(ByVal strSearchClue As SqlString, ByVal strStringtoSearch As SqlString) As Long

    Dim intMiss As Integer = 0
    Dim intRet As Integer
    Static Dim sClue As String = ""

    xudf_fuzzy = 0

    ' we only need to set the clue whenever it changes '
    If (sClue <> strSearchClue.ToString) Then
        sClue = strSearchClue.ToString
        intMiss = (Len(sClue) \ 4) + 1
        intRet = setClue(sClue, intMiss)
    End If

    ' return the fuzzy match result (0 or 1) '
    xudf_fuzzy = srchString(strStringtoSearch.ToString)

End Function
fuzzy.h
typedef struct {
short int INVRT, AND, LOWER, COMPL, Misses;
long int num_of_matched;
int D_length;
unsigned long int endposition, D_endpos;
unsigned long int Init1, NOERRM;
unsigned long int Mask[SYMMAX];
unsigned long int Init[MaxError];
unsigned long int Bit[WORDSIZE+1];
unsigned char prevpat[MaxDelimit];
unsigned char _buffer[Max_record+Max_record+256];
unsigned char _myPatt[MAXPAT];
} SRCH_STRUCT;


fuzzy.c
#include <sys/types.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <wtypes.h>
#include <time.h>
#include "fuzzy.h"

// call exports
__declspec(dllexport) int CALLBACK setClue(char**, int*);
__declspec(dllexport) int CALLBACK srchString(char**);

SRCH_STRUCT STRCT = { 0 };
int cluePrep(unsigned char []);
int srchMin(unsigned char [], int);

BOOL APIENTRY DllMain( HANDLE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved )
{
    switch (ul_reason_for_call)
    {
        case DLL_PROCESS_ATTACH:
        case DLL_THREAD_ATTACH:
        case DLL_THREAD_DETACH:
        case DLL_PROCESS_DETACH:
        break;
    }
    return TRUE;
}

int CALLBACK setClue(char **pattern, int *misses)
{
    int i;
    unsigned char *p;

    // code to do initialization stuff, set flags etc. etc.    
        STRCT.Misses = (int)misses;
        p = &(STRCT._myPatt[2]);
        STRCT._myPatt[0] = '\n';
        STRCT._myPatt[1] = SEPCHAR;
        strcpy((char *)p, *pattern);
        //blah blah
    // end setup stuff

    i = cluePrep(STRCT._myPatt);

    return 0;
}


int CALLBACK srchString(char **textstr)
{
    int res,i = Max_record;
    unsigned char c;
    char *textPtr = *textstr;

    STRCT.matched = 0;

    //clean out any non alphanumeric characters while we load the field to be tested
    while ((c = *textPtr++)) if ( isalpha(c) || isdigit(c) || c == ' ' ) STRCT._buffer[i++] = c;
    STRCT._buffer[i] = 0;

    // do the search
    res =  srchMin(STRCT.pattern, STRCT.Misses);

    if (res < 0) return res;

    return STRCT.matched;

}