VB6之多维数组中元素在内存中的排列情况

 Private Declare Sub RtlMoveMemory Lib "kernel32" (Destination As Any, Source As Any, ByVal Length As Long)

 'code by lichmama from cnblogs.com
Private Sub Form_Load()
Dim a() As Byte
Dim b(, ) As Byte
Dim c(, , ) As Byte Debug.Print "一维数组:"
Debug.Print VarPtr(a()), VarPtr(a()), VarPtr(a())
'数组元素在内存中的排列情况:
'a[0]|a[1]|a[2] Debug.Print "二维数组:"
Debug.Print VarPtr(b(, )), VarPtr(b(, )), VarPtr(b(, ))
Debug.Print VarPtr(b(, )), VarPtr(b(, )), VarPtr(b(, ))
Debug.Print VarPtr(b(, )), VarPtr(b(, )), VarPtr(b(, ))
'数组元素在内存中的排列情况:
'b[0,0]|b[1,0]|b[2,0]-->b[0,1]|b[1,1]|b[2,1]-->b[0,2]|b[1,2]|b[2,2] Debug.Print "三维数组:"
Debug.Print VarPtr(c(, , )), VarPtr(c(, , )), VarPtr(c(, , ))
Debug.Print VarPtr(c(, , )), VarPtr(c(, , )), VarPtr(c(, , ))
Debug.Print VarPtr(c(, , )), VarPtr(c(, , )), VarPtr(c(, , ))
Debug.Print VarPtr(c(, , )), VarPtr(c(, , )), VarPtr(c(, , ))
Debug.Print VarPtr(c(, , )), VarPtr(c(, , )), VarPtr(c(, , ))
Debug.Print VarPtr(c(, , )), VarPtr(c(, , )), VarPtr(c(, , ))
Debug.Print VarPtr(c(, , )), VarPtr(c(, , )), VarPtr(c(, , ))
Debug.Print VarPtr(c(, , )), VarPtr(c(, , )), VarPtr(c(, , ))
Debug.Print VarPtr(c(, , )), VarPtr(c(, , )), VarPtr(c(, , ))
'数组元素在内存中的排列情况:
'c[0,0,0]|c[1,0,0]|c[2,0,0]-->c[0,1,0]|c[1,1,0]|c[2,1,0]-->c[0,2,0]|c[1,2,0]|c[2,2,0]
'-->c[0,0,1]|c[1,0,1]|c[2,0,1]-->c[0,1,1]|c[1,1,1]|c[2,1,1]-->c[0,2,1]|c[1,2,1]|c[2,2,1]
'-->c[0,0,2]|c[1,0,2]|c[2,0,2]-->c[0,1,2]|c[1,1,2]|c[2,1,2]-->c[0,2,2]|c[1,2,2]|c[2,2,2] '我们习惯逻辑上这么给数组赋值,字面上像是b()="lhmimaca!"
b(, ) = &H6C: b(, ) = &H68: b(, ) = &H6D
b(, ) = &H69: b(, ) = &H6D: b(, ) = &H61
b(, ) = &H63: b(, ) = &H61: b(, ) = &H21 Dim text As String
text = String(, " ")
Call RtlMoveMemory(ByVal StrPtr(text), ByVal VarPtr(b(, )), )
Debug.Print "但,其实结果是这样的:";
Debug.Print StrConv(text, vbUnicode)
End Sub

看结果说话(内存地址打印):

一维数组:

二维数组:

三维数组:

但,其实结果是这样的:lichmama!         
上一篇:JAVA实现Excel批量导入


下一篇:Java Struts2 POI创建Excel文件并实现文件下载