private bool Init(List <Word> words) { if (words.Count == 0) { return(false); } var wordsCount = words.Count; if (_pinnedWordsBufferSize < wordsCount) { ReAllocPinnedWordsBuffer(wordsCount); } for (var i = 0; i < wordsCount; i++) { var word = words[i]; var gcHandle = GCHandle.Alloc(word.valueUpper, GCHandleType.Pinned); var basePtr = (char *)gcHandle.AddrOfPinnedObject().ToPointer(); PinnedWord *pw = _pinnedWordsBufferPtrBase + i; pw->basePtr = basePtr; pw->gcHandle = gcHandle; pw->posTaggerInputType = word.posTaggerInputType; pw->posTaggerExtraWordType = word.posTaggerExtraWordType; pw->length = word.valueUpper.Length; } return(true); }
private void DisposePinnedWordsBuffer() { if (_pinnedWordsBufferPtrBase != null) { _pinnedWordsBufferGCHandle.Free(); _pinnedWordsBufferPtrBase = null; } }
private void ReAllocPinnedWordsBuffer(int newBufferSize) { DisposePinnedWordsBuffer(); _pinnedWordsBufferSize = newBufferSize; var pinnedWordsBuffer = new PinnedWord[_pinnedWordsBufferSize]; _pinnedWordsBufferGCHandle = GCHandle.Alloc(pinnedWordsBuffer, GCHandleType.Pinned); _pinnedWordsBufferPtrBase = (PinnedWord *)_pinnedWordsBufferGCHandle.AddrOfPinnedObject().ToPointer(); }