Issues of stdRefArray

Chiusa
#145 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
38/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
visualbasic
Ambito
tooling

Direzione di ricerca

Start by locating the stdRefArray implementation and reproducing the TeststdRefArray2 and TeststdRefArray3 examples from the issue. Compare the current array access behavior with the requested VarPtrArr and default-property behavior, then verify that both examples produce the stated reads and writes without changing the intended reference semantics.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

enhancement
  1. VarPtrArr shall be reurn the pointer of the safearray address.
#If Win64 Then
Private Function VarPtrArr(ByRef arr As Variant) As LongLong
#Else
Private Function VarPtrArr(ByRef arr As Variant) As Long
#End If

Dim vt As VbVarType
Dim p As Long
p = VarPtr(arr)
CopyMemory vt, ByVal p, 2

If (vt And vbArray) = vbArray Then '//安全数组
    VarPtrArr = PtrAdd(p, 8) 'VARIANT结构中wReserved2的地址
    
    If (vt And &H4000) = &H4000 Then     '//引用类型VT_BYREF,如果是引用类型则wReserved2的值才是数组地址的地址
        CopyMemory VarPtrArr, ByVal VarPtrArr, PTR_SIZE
    End If
End If
End Function
Private Function PtrAdd(ByVal Ptr As LongPtr, ByVal iOffset As Long) As LongPtr
    ' For adding (or subtracting) a small number from a pointer.
    ' Use PtrAddEx for adding (or subtracting) large numbers from a pointer.
    PtrAdd = (Ptr Xor &H80000000) + iOffset Xor &H80000000
End Function
  1. It is better to provide a default property to use it like a real array. But there is some CopyMemory cost that it shall not be used in a loop
Property Get GetData()
Attribute GetData.VB_UserMemId = 0
Call CopyMemory(GetData, data, 16)
End Property

Sub TeststdRefArray2()
Dim arr As Variant: arr = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
Dim rarr As stdRefArray: Set rarr = stdRefArray.Create(arr)
Debug.Print rarr(1)  '=> 2
rarr(1) = 3
Debug.Print rarr(1)  '=> 3
Debug.Print rarr(2)  '=> 3
End Sub

Sub TeststdRefArray3()
Dim arr As Variant: arr = [M1:M3]

Dim rarr As stdRefArray: Set rarr = stdRefArray.Create(arr)
Debug.Print rarr(1, 1) '=> 2
rarr(1, 1) = 3
Debug.Print rarr(1, 1) '=> 3
Debug.Print rarr(2, 1) '=> 3
End Sub
Lingua principale
VBA
Stelle
412
Fork
70
Merge medio
17h 22m
PR unite (30g)
22

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di sancarn/stdVBA

Tutte le issue di sancarn/stdVBA

Issue simili

Altre issue su DevTools

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.