How to copy a string to a memory address in the fastest way, including the first 4 bytes.
Or
Copy a string to a memory address in the fastest way, including the first 4 bytes.
'=============
how to write string to memory address by asm code?
how to read string from memory by pointer for CreateFileMapping?
how to read data without api(RtlMoveMemory),use pointer is best.
vb6 activex exe ,or activex.dll,ocx,for read data or call method,activex.exe very slowly,set value 1000000000 times,need 13000 Seconds.;
dll,ocx,need 100 second,
copymemory use:10 ms,
a(x)=n,,use 1 ms
use api "CreateFileMapping" ,share memory area by name like "memory_abc",read it from other process。
To share data between processes, you need to open this "shared file name" and then use copymemory (RtlMoveMemory) to write or read data.
Is there such a method, the second process creates a variable, such as: dim str2 as string, or dim strArr () as string, and then directly access the memory data using the variable name, without RtlMoveMemory faster
chinese:进程之间共享数据需要打开这个"共享文件的名称",再用copymemory(RtlMoveMemory)写入或者读取数据。
有没有这样一种方法,第二个进程创建一个变量,比如:dim str2 as string,或者 dim strArr() as string,然后直接用变量名进行访问内存数据,不用RtlMoveMemory速度更快
Last edited by xiaoyao; Feb 16th, 2020 at 03:53 AM.
Re: how to read string from "CreateFileMapping" by pointer?
http://www.xbeat.net/vbspeed/i_VBVM6Lib.html
Dim sSource As String
Dim sStolen As String
' ...
sStolen = StringRef(sSource)
' sStolen and sSource now point
' to the same characters
Option Explicit
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Declare Function GetProcessHeap Lib "kernel32" () As Long
Private Declare Function HeapAlloc Lib "kernel32" _
(ByVal hHeap As Long, ByVal dwFlags As Long, _
ByVal dwBytes As Long) As Long
Private Declare Function HeapFree Lib "kernel32" _
(ByVal hHeap As Long, ByVal dwFlags As Long, _
lpMem As Any) As Long
Private Declare Sub CopyMemoryPut Lib "kernel32" Alias _
"RtlMoveMemory" (ByVal Destination As Long, _
Source As Any, ByVal Length As Long)
Private Declare Sub CopyMemoryRead Lib "kernel32" Alias _
"RtlMoveMemory" (Destination As Any, _
ByVal Source As Long, ByVal Length As Long)
Dim pHead As Long
Private Type ListElement
strData As String * 255 '==255 * 2=500 bytes vbStrings are UNICODE !
pNext As Long '4 bytes
'pointer to next ; ==0 if end of list
'----------------
'total: 504 bytes
End Type
Private Sub CreateLinkedList()
'add three items to list
' get the heap first
Dim pFirst As Long, pSecond As Long 'local pointers
Dim hHeap As Long
hHeap = GetProcessHeap()
'allocate memory for the first and second element
pFirst = HeapAlloc(hHeap, 0, 504)
pSecond = HeapAlloc(hHeap, 0, 504)
If pFirst <> 0 And pSecond <> 0 Then
'memory is allocated
PutDataIntoStructure pFirst, "Hello", pSecond
PutDataIntoStructure pSecond, "Pointers", 0
pHead = pFirst
End If
'put he second element in the list
End Sub
Private Sub Command1_Click()
CreateLinkedList
ReadLinkedListDataAndFreeMemory
End Sub
Private Sub PutDataIntoStructure(ByVal ptr As Long, _
szdata As String, ByVal ptrNext As Long)
Dim le As ListElement
le.strData = szdata
le.pNext = ptrNext
CopyMemoryPut ptr, le, 504
End Sub
Private Sub ReadDataToStructure(ByVal ptr As Long, _
struct As ListElement)
Dim le As ListElement
CopyMemoryRead le, ptr, 504
struct.strData = le.strData
struct.pNext = le.pNext
End Sub
'Private Sub ReadDataToStructure(ByVal ptr As Long, _
' struct As ListElement) ' why it's err?
' CopyMemoryRead struct, ptr, 504 ' why it's err?
'End Sub
Private Sub ReadLinkedListDataAndFreeMemory()
Dim pLocal As Long
Dim hHeap As Long
Dim le As ListElement
Dim strData As String
pLocal = pHead
hHeap = GetProcessHeap()
Do While pLocal <> 0
ReadDataToStructure pLocal, le
strData = strData & vbCrLf & le.strData
HeapFree hHeap, 0, pLocal
pLocal = le.pNext
Loop
MsgBox strData
End Sub
Private Sub ReadDataToStructure(ByVal ptr As Long, _
struct As ListElement) ' why it's err?
CopyMemoryRead struct, ptr, 504 ' why it's err?
End Sub
Last edited by xiaoyao; Feb 9th, 2020 at 07:14 AM.
Re: how to read string from pointer by CreateFileMapping?
What's your the end goal? If you want to read a string you need to decide if you want to have a copy or you just want to refer to that variable. To refer a variable you can use Long pointer.
Re: how to read string from pointer by CreateFileMapping?
Originally Posted by The trick
What's your the end goal? If you want to read a string you need to decide if you want to have a copy or you just want to refer to that variable. To refer a variable you can use Long pointer.
j
want to refer to that variable. To refer a variable you can use Long pointer.
I want to read a.exe string variable from other process(b.exe)
If I use rot or activex.exe to call a function or Getting property values, reading and writing are slow,so I think what way cay read string variable quickly?
I testing use copymemory by createfilemaping is quickly,How can I use pointers to run faster?
Re: how to read string from pointer by CreateFileMapping?
I want to read a.exe string variable from other process(b.exe)
If you want to read an arbitrary BSTR string then you could use ReadProcessMemory because the string can have an arbitrary length.
If you want to just share a string data between 2 processes you can use FileMapping/Shared section. There are many the FileMapping examples here i'll show how to do such mapping based on the shared section.
For example, let's say you have enough buffer size 4096 bytes (which 2046-symbols BSTR content). You can create an Obj (COFF) file with the initial content and then link it to main executable (i used FASM):
Code:
format MS COFF
section '.shdata' data readable writable shareable
public StringContent as "StringContent"
start_sec:
dd @f - $ + 4 ; Length prefix
StringContent: du "Hello world!", 0
@@:
It produces the Obj file with the shared section ".shdata". This section is shared between all the process instances. You can be sure the section has the 4096 bytes size because alignment (if you don't change it).
Then you can just compile and export that symbol. I made a small example which show how to access to that content. Notice it works only in compiled form (you need to "emulate" the shared section thru FileMapping in IDE).
Code:
Option Explicit
Private Declare Function GetProcAddress Lib "kernel32" ( _
ByVal hModule As Long, _
ByVal lpProcName As String) As Long
Private Declare Function GetMem4 Lib "msvbvm60" ( _
ByRef src As Any, _
ByRef Dst As Any) As Long
Private Declare Function GetWindowText Lib "user32" _
Alias "GetWindowTextW" ( _
ByVal hwnd As Long, _
ByRef lpString As Any, _
ByVal cch As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32" _
Alias "GetWindowTextLengthW" ( _
ByVal hwnd As Long) As Long
Private m_sSharedString As String
Private Sub cmdRead_Click()
txtText.Text = m_sSharedString
End Sub
Private Sub cmdWrite_Click()
GetWindowText txtText.hwnd, ByVal StrPtr(m_sSharedString), 2046 ' // 4096 page size - 4 pfx len and 2 bytes per char
GetMem4 GetWindowTextLength(txtText.hwnd) * 2, ByVal StrPtr(m_sSharedString) - 4
End Sub
Private Sub Form_Load()
Dim pString As Long
pString = GetProcAddress(0, "StringContent")
GetMem4 pString, ByVal VarPtr(m_sSharedString)
End Sub
Private Sub Form_Unload(Cancel As Integer)
GetMem4 0&, ByVal VarPtr(m_sSharedString)
End Sub
You can run the several instances and try to read/write the content.
Re: how to read string from pointer by CreateFileMapping?
Originally Posted by The trick
If you want to read an arbitrary BSTR string then you could use ReadProcessMemory because the string can have an arbitrary length.
If you want to just share a string data between 2 processes you can use FileMapping/Shared section. There are many the FileMapping examples here i'll show how to do such mapping based on the shared section.
For example, let's say you have enough buffer size 4096 bytes (which 2046-symbols BSTR content). You can create an Obj (COFF) file with the initial content and then link it to main executable (i used FASM):
Code:
format MS COFF
section '.shdata' data readable writable shareable
public StringContent as "StringContent"
start_sec:
dd @f - $ + 4 ; Length prefix
StringContent: du "Hello world!", 0
@@:
It produces the Obj file with the shared section ".shdata". This section is shared between all the process instances. You can be sure the section has the 4096 bytes size because alignment (if you don't change it).
Then you can just compile and export that symbol. I made a small example which show how to access to that content. Notice it works only in compiled form (you need to "emulate" the shared section thru FileMapping in IDE).
Code:
Option Explicit
Private Declare Function GetProcAddress Lib "kernel32" ( _
ByVal hModule As Long, _
ByVal lpProcName As String) As Long
Private Declare Function GetMem4 Lib "msvbvm60" ( _
ByRef src As Any, _
ByRef Dst As Any) As Long
Private Declare Function GetWindowText Lib "user32" _
Alias "GetWindowTextW" ( _
ByVal hwnd As Long, _
ByRef lpString As Any, _
ByVal cch As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32" _
Alias "GetWindowTextLengthW" ( _
ByVal hwnd As Long) As Long
Private m_sSharedString As String
Private Sub cmdRead_Click()
txtText.Text = m_sSharedString
End Sub
Private Sub cmdWrite_Click()
GetWindowText txtText.hwnd, ByVal StrPtr(m_sSharedString), 2046 ' // 4096 page size - 4 pfx len and 2 bytes per char
GetMem4 GetWindowTextLength(txtText.hwnd) * 2, ByVal StrPtr(m_sSharedString) - 4
End Sub
Private Sub Form_Load()
Dim pString As Long
pString = GetProcAddress(0, "StringContent")
GetMem4 pString, ByVal VarPtr(m_sSharedString)
End Sub
Private Sub Form_Unload(Cancel As Integer)
GetMem4 0&, ByVal VarPtr(m_sSharedString)
End Sub
You can run the several instances and try to read/write the content.
IT'S ONLY suppot THE SAme process,i want to read write string ,from 2 process
Re: how to read string from pointer by CreateFileMapping?
Code:
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "MemoryGx"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
Const SECTION_MAP_WRITE = &H2
Const SECTION_MAP_READ = &H4
Const FILE_MAP_WRITE = SECTION_MAP_WRITE
Const FILE_MAP_READ = SECTION_MAP_READ
Const PAGE_READONLY = &H2
Const PAGE_READWRITE = &H4
Const ERROR_ALREADY_EXISTS = 183&
Const ERROR_INVALID_DATA = 13&
Private Declare Function CreateFileMapping Lib "kernel32" Alias "CreateFileMappingA" _
(ByVal hFile As Long, lpFileMappigAttributes As Any, _
ByVal flProtect As Long, ByVal dwMaximumSizeHigh As Long, ByVal dwMaximumSizeLow As Long, ByVal lpName As String) As Long
Private Declare Function MapViewOfFile Lib "kernel32" (ByVal hFileMappingObject As Long, ByVal dwDesiredAccess As Long, ByVal dwFileOffsetHigh As Long, ByVal dwFileOffsetLow As Long, ByVal dwNumberOfBytesToMap As Long) As Long
Private Declare Function UnmapViewOfFile Lib "kernel32" (lpBaseAddress As Any) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" ( _
lpvDest As Any, lpvSource As Any, ByVal cbCopy As Long)
Private FileMapHd As Long, ErrCode As Long
Const MEM_HANDLE As Long = -1&
Public Len1 As Long
Public VarptrAddress As Long, FileMapPtr As Long
Dim bt() As Byte
Dim StrLenb As Long
Dim StrCount As Long
'以下代码复制到窗体中使用-------------------AAA
'Public Memory As New MemoryGx
'Private Sub Command1_Click()
'Dim S As String
'Memory.Create "time"
'S = Now
'Memory.Data = S
'MsgBox S
'End Sub
'
'Private Sub Command2_Click()
'Dim S As String
'Memory.Create "time"
'S = Memory.Data
'MsgBox S
'End Sub
'------------------------>>>>TestEnd---------AAA
'产生一个记忆体对应档,名称为sName
'该记忆体对应档里面存的资料分成两部份
'一个Long值,代表字串的长度,另一为字串,这字串才是要Share部份
Function Create(sName As String) As Boolean
Create = False
If sName = "" Then Exit Function
' Try to create file mapping of 65535 (only used pages matter)
FileMapHd = CreateFileMapping(MEM_HANDLE, ByVal 0, PAGE_READWRITE, _
0, 65535, sName)
'如果sName原本就存在,则传回的h值是先前Call CreateFileMapping的handle of file Mapping Object
'而且Err.LastDllError 传回的是ERROR_ALREADY_EXISTS,如果sName原来不存在,则传回新的Handle值
'且Err.LastDllError = 0
ErrCode = Err.LastDllError
' Unknown error, bail out
'原:If ClearFirst And FileMapHd = 0 Then ClearMemory: Exit Function
' Get pointer to mapping
'If ErrCode <> 0 Then ClearMemory
FileMapPtr = MapViewOfFile(FileMapHd, FILE_MAP_WRITE, 0, 0, 0)
If FileMapPtr = 0 Then ErrCode = Err.LastDllError: Exit Function
If ErrCode <> ERROR_ALREADY_EXISTS Then
' Set size of new file mapping to 0 by copying first 4 bytes
Dim Len1 As Long ' = 0
'将0放入记忆体对应档中的前4个Byte
CopyMemory ByVal FileMapPtr, Len1, 4
' Else
' Existing file mapping
End If
ErrCode = 0
Create = True
VarptrAddress = FileMapPtr + 4
'MsgBox FileMapHd & "/" & FileMapPtr
End Function
' Property Get Data() As String
' If FileMapHd = 0 Or FileMapPtr = 0 Then ErrCode = ERROR_INVALID_DATA: Exit Property
' Dim Len1 As Long, sData As String
' CopyMemory Len1, ByVal FileMapPtr, 4
' ' Copy rest of memory into string
' If Len1 = 0 Then Exit Property ' Data = sEmpty
' sData = String$(Len1, 0)
' '将字串放入记忆体对应档中的第4个Byte之後
' CopyMemory ByVal sData, ByVal (FileMapPtr + 4), Len1
' Data = sData
' End Property
Property Get Data() As String
If FileMapHd = 0 Or FileMapPtr = 0 Then ErrCode = ERROR_INVALID_DATA: Exit Property
CopyMemory Len1, ByVal FileMapPtr, 4
' Copy rest of memory into string
If Len1 = 0 Then Exit Property ' Data = sEmpty
Data = String$(Len1, 0)
'将字串放入记忆体对应档中的第4个Byte之後
CopyMemory ByVal Data, ByVal (VarptrAddress), Len1
End Property
Property Let Data(S As String)
If FileMapHd = 0 Or FileMapPtr = 0 Then ErrCode = ERROR_INVALID_DATA: Exit Property
Len1 = LenB(StrConv(S, vbFromUnicode)) + 2 'abc中国,长度=7,10
'MsgBox "Len1=" & Len1 & "," & Len(S) * 2
' Copy length to first 4 bytes and string to remainder
CopyMemory ByVal FileMapPtr, Len1, 4
CopyMemory ByVal (VarptrAddress), ByVal S, Len1
End Property
Sub SetMemString(S As String)
StrCount = Len(S)
bt = S
StrLenb = UBound(bt) + 1 'abc中国,长度=7,10
MsgBox "BT长度" & StrLenb
CopyMemory ByVal FileMapPtr, StrCount, 4
CopyMemory ByVal (VarptrAddress), bt(0), StrLenb
End Sub
Property Get LastErr() As Long
LastErr = ErrCode
End Property
Public Sub ClearMemory()
Dim i As Long
i = UnmapViewOfFile(FileMapPtr)
i = CloseHandle(FileMapHd)
FileMapHd = 0
FileMapPtr = 0
End Sub
Private Sub Class_Terminate()
If FileMapHd <> 0 Then ClearMemory
End Sub
code in memorygx.cls
code in bas:
Code:
Attribute VB_Name = "Module1"
Option Explicit
Public Declare Function ArrayPtr Lib "msvbvm60.dll" Alias "VarPtr" (ptr() As Any) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Declare Sub ZeroMemory Lib "kernel32.dll" Alias "RtlZeroMemory" (Destination As Any, ByVal Length As Long)
Public StrArr(0) As String, X As Long
Public Type LongPtr
Dimensions As Integer
MustBe0x96 As Integer
SizeOfType As Long
MustBeOne As Long
Pointer As Long
MustBeIntMax As Long
LBound As Long
Value() As Long
End Type
Public p1 As LongPtr, cnstr() As String
Sub LongPtr_Setup(Thing As LongPtr, ByVal SrcData_Ptr As Long)
Thing.Dimensions = 1
Thing.MustBe0x96 = &H96
Thing.SizeOfType = 4
Thing.MustBeOne = 1
Thing.Pointer = SrcData_Ptr
Thing.MustBeIntMax = -1
Thing.LBound = 0
CopyMemory ByVal ArrayPtr(Thing.Value()), VarPtr(Thing), 4
End Sub
code in form:
Code:
Private Sub Command3_Click()
MsgBox cnstr(0)
End Sub
Private Sub Command4_Click()
'write string to filemapping
Mem.SetMemString Text1.Text
MsgBox "ok"
End Sub
Private Sub Form_Load()
ReDim cnstr(0)
LongPtr_Setup p1, VarPtr(cnstr(0)) '模拟指针绑定
Set Mem = New MemoryGx
Mem.Create "str1"
'Mem.Data = "TestAbc"
p1.Value(0) = Mem.VarptrAddress
end sub
read filemapping memory string variable by pointer,it's quickly:
MsgBox cnstr(0)
how to write string quickly?
Last edited by xiaoyao; Feb 11th, 2020 at 04:22 AM.
Re: how to read string from pointer by CreateFileMapping?
So you are copying the string into memory that's accessible from unmanaged code, but it's still only accessible from the process that called Marshal.StringToHGlobalAuto.
Options
1. Place the string in the Global Atom Table
2. Use shared memory i.e. a mem mapping
3. Use regular DDE
4. Use COM
5. Use Remoting
6. Use WFC
Update
Create an unmanaged dll in c or c++ and declare a shared memory segment.
link.exe /SECTION documentation[^]
#pragma data_seg(".JSOP")
wchar_t SharedBufferArea[2048]; // <-- This area is shared
#pragma data_seg()
// rws:
// r - Read,
// w - write,
// s - Shares the section among all processes that load the image
Re: how to read string from pointer by CreateFileMapping?
Originally Posted by The trick
No it supports as many process as possible. Just run the several copies and check the result.
HOW TO READ MEMORY STRING BY "SAFEARRAY"
Code:
Private Type SAFEARRAYBOUND
cElements As Long
lLbound As Long
End Type
Private Type SAFEARRAY
cDims As Integer
fFeatures As Integer
cbElements As Long
cLocks As Long
pvData As Long
Bounds As SAFEARRAYBOUND
End Type
i want to bind string variable(public myabc as string) to memory address abc_Addr.
so if i change myabc value to "hello",then i can read the same value (hello)
how can i do for best? for run quickly, i want to bind string variable pointer to memory address
now i have a way:
Code:
in base file:
Public p1 As LongPtr, cnstr() As String*200
in form
ReDim cnstr(0)
LongPtr_Setup p1, VarPtr(cnstr(0))
so i can change memory data by :
cnstr(0)="china"
msgbox cnstr(0)
it's good。But fixed length, followed by many spaces.
If the length is also written when the data is written, the actual data can be obtained by left (cnstr (0), len (1)) during reading.
It's better not to use fixed length string array variables. Do you have any way?
Re: how to read string from memory by pointer for CreateFileMapping?
This function I am mainly used to copy the binding of memory addresses and string variables. Do a memory file mapping, and then different processes can directly access memory by using string name variables. Here, the safe array and pointer methods are used.
chinese:这个功能我现在主要用于拷贝内存地址和字符串变量的绑定。搞一个内存文件映射,然后不同的进程可以直接用字符串名变量的方式直接访问内存,这里使用了安全数组和指针的方法。
how to read string from memory by pointer for CreateFileMapping? http://www.vbforums.com/showthread.p...ateFileMapping
dim ptrstr1 as string '* ptr
dim lenarr() as long '* ptr
dim strarr() as long *100 '* ptr +4
so I can use:
write string:
lenarr(0)=lenb(s)
strrarr(0)=s
readstring from filemapping(memory):
msgbox ptrstr1
it's a way to read/write memory without api calling for run quickly。
it's used for share variable to more process.
write abc.exe "dim ptrstr1 as string",read from abc2.exe by ptrstr1。
Just as multiple threads can access global variables in a process, we now implement global variables for multiple processes. .
Re: how to read string from memory by pointer for CreateFileMapping?
Multi-threading can access all global variables in the software, including forms, objects, and controls.
Now I am sharing all the variables between multiple processes, if I can share the variables between multiple computers.
It's a bit like an in-memory database(mongo).
chinese:多线程可以访问软件里面的所有全局变量,包括窗体还有对象,控件。
现在我是把多个进程之间的变量全部共享了,如果可以把多台电脑之间也可以共享变量。
有点像是内存数据库mongo的味道。
Unicode strings use two bytes per character, so the receiving buffer must be twice as large as lstrlenW indicates. The byte array may be assigned directly to the PointerToStringW return value, because it's already in the native string format used by VB.
PointerToStringW,use api,i only want to find a way readm string ,without api.
Code:
Private Declare Sub CopyMemory Lib "kernel32" Alias _
"RtlMoveMemory" (pTo As Any, pFrom As Any, ByVal lSize As Long)
Private Declare Function lstrlenW Lib "kernel32" (ByVal PointerToString _
As Long) As Long
Private Function PointerToStringW(ByVal lpStringW As Long) As String
Dim Buffer() As Byte
Dim nLen As Long
If lpStringW Then
' Double the retval of lstrlenW
' for proper buffer size.
nLen = lstrlenW(lpStringW) * 2
If nLen Then
ReDim Buffer(0 To (nLen - 1)) As Byte
CopyMemory Buffer(0), ByVal lpStringW, nLen
PointerToStringW = Buffer
End If
End If
End Function
Re: how to read string from "CreateFileMapping" by pointer?
Originally Posted by xiaoyao
http://www.xbeat.net/vbspeed/i_VBVM6Lib.html
Dim sSource As String
Dim sStolen As String
' ...
sStolen = StringRef(sSource)
' sStolen and sSource now point
' to the same characters
Function StringRef(BSTR As String) As String
Example:
Dim sSource As String
Dim sStolen As String
' ...
sStolen = StringRef(sSource)
' sStolen and sSource now point
' to the same characters
' ...
' Clean up
StringPtr(sStolen) = 0&
================
dim ptrstr1 as string '* ptr
dim lenarr() as long '* ptr
dim strarr() as long *100 '* ptr +4
so I can use:
write string:
lenarr(0)=lenb(s)
strrarr(0)=s
readstring from filemapping(memory):
msgbox ptrstr1
I NEED USE STRING ARRAY TO BIND POINT(SAVEARRY)
IF ONLY BIND STRING Variables are best。
how do "StringRef" for memory address ,use ctreatefilemapping?
-=-==========
qustion 2:
How do 2 lines of code merge into one call,like asm code?
sub putstr(s as string)
lenarr(0)=lenb(s)
strrarr(0)=s
end sub
sub putstr(s1 as string)
CopyMemory ByVal Mem.FileMapPtr, ByVal StrPtr(S1) - 4, Lenb(S1) + 4
'how to get this asm code?
i want to copy string byte with length to memory address.
end sub
Sub CopyStrToAddress(StrPtr1 As Long, MemAddress As Long)
'把字符串地址的数据,复制到另一个内存地址
'数据长度=(StrPtr1-4)的地方 4字节的LONG值
'复制算法:
'CopyMem MemAddress, ByVal StrPtr1 - 4, 数据长度 + 4
CopyMem StrLeN, ByVal StrPtr1 - 4, 4
CopyMem MemAddress, ByVal StrPtr1 - 4, StrLeN + 4
end sub
how to copy bstr byte to memory address by asm? or without api?
Last edited by xiaoyao; Feb 15th, 2020 at 11:39 PM.
Re: how to read string from memory by pointer for CreateFileMapping?
vbaStrCopy copies a string to memory, similar to the Windows API HMEMCPY
b) __vbaVarCopy copies a variable value string to memory
__vbaVarMove variable moves in memory, or copies a variable value string to memory
or can put address of vbaStrCopy,run in asm?
Re: how to read string from memory by pointer for CreateFileMapping?
it's like a memory database for more process read/write,(mongo).
type fields
id as long
name as string
date1 as date
'more fields
end type
public RowData(rows=100) as fields
'it's like a table
Sorry, my English is not very good. Reading the length of a string is just one function inside. The ultimate goal is that I still want to be able to share string arrays or structure variables. Structure arrays are shared by memory so that multiple processes can read these information at the same time. Reading is simple. I just want to make it run faster and more efficiently. For example, if I want to read out a string, the ordinary method needs to dynamically allocate string space every time, read the length and copy it in.
With a good method, reading and writing to shared memory data does not need to call any api.
chinese:我使用自动翻译软件,所以很多意义可能表达不清楚,所以我会把中文同时发上来,你们可以用翻译软件把中文翻译成英文。
对不起,我的英文不太好。读取字符串长度只是里面的一个功能。最终目标我还是希望能够把字符串数组或者结构变量,结构数组通过内存共享,让多个进程可以同时读取这些信息,读取很简单我只是希望能够让他 运行更快,效 率更高。比如我要把字符串读出来,普通方法需要每次动态分配字符串空间,读取长度再拷贝进去。用了好的方法,读取写入共享内存数据就不需要调用任何api。
Re: vb6 memory database like "mongo" by cteatefilemapping
I'm more interested in these topics:
sqlite memory database
how to use fastdb.dll in vb6
mongo,sqlserver memory db
how to create ramdisk by vb6?
how to open a word file from memory address,can edit by word.exe?
(not disk file)
how to pack abc.exe,1.dll,2.dll to abc2.dll,Become a single file, you can run without releasing the dll.
Re: vb6 memory database like "mongo" by cteatefilemapping
If you modify your question in Post #1, then you should display your modified part in bold or blue font, or, it's better that you post a new thread to ask your new question. Your original threads/posts are too confusing.
Edit:
In addition, if you want to use sqlite memory db, then you'd better learn vbRichClient5 seriously, it's the best SqliteDB wrapper for VB6 in the world.
Last edited by dreammanor; Feb 16th, 2020 at 03:14 AM.
Re: vb6 memory database like "mongo" by cteatefilemapping
Originally Posted by dreammanor
If you modify your question in Post #1, then you should display your modified part in bold or blue font, or, it's better that you post a new thread to ask your new question. Your original threads/posts are too confusing.
Edit:
In addition, if you want to use sqlite memory db, then you'd better learn vbRichClient5 seriously, it's the best SqliteDB wrapper for VB6 in the world.
Not many people may be interested in this technical issue. Ordinary people just need to be able to implement functions, few people will go for efficiency and speed.
chinese: 关于这个技术问题,可能感兴趣的人不多。普通人只要能实现功能就好了,很少有人会去追求效率和速度。
Re: Can anyone write assembly code to copy a string?
i don't know why, but your threads are giv'in me a headache
to hunt a species to extinction is not logical !
since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.
Re: Can anyone write assembly code to copy a string?
Originally Posted by xiaoyao
Not many people may be interested in this technical issue. Ordinary people just need to be able to implement functions, few people will go for efficiency and speed.
chinese: 关于这个技术问题,可能感兴趣的人不多。普通人只要能实现功能就好了,很少有人会去追求效率和速度。
Professional developers attach great importance to efficiency and speed, but they are pursuing overall efficiency and speed, not at a certain technical point. Olaf, wqweto and The trick are not only proficient in VB, but also C, C ++, and assembly. Obviously, your problems are very simple for them. But the way you ask questions is really bad.
In addition, posting Chinese will not make others better understand what you mean, but it will cause everyone a headache and leave your thread. No one wants to see a bunch of text symbols in the thread that they can't understand.
Last edited by dreammanor; Feb 16th, 2020 at 04:15 AM.
Re: Can anyone write assembly code to copy a string?
Originally Posted by dreammanor
Professional developers attach great importance to efficiency and speed, but they are pursuing overall efficiency and speed, not at a certain technical point. Olaf, wqweto and The trick are not only proficient in VB, but also C, C ++, and assembly. Obviously, your problems are very simple for them. But the way you ask questions is really bad.
In addition, posting Chinese will not make others better understand what you mean, but it will cause everyone a headache and leave your thread. No one wants to see a bunch of text symbols in the thread that they can't understand.
thanks, for that !
to hunt a species to extinction is not logical !
since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.
Re: Can anyone write assembly code to copy a string?
Should I add please ignore Chinese? Because I used translation software to translate Chinese into English, the translation was inaccurate, so the original Chinese was retained. In fact, all my Chinese questions can be ignored. Just like a software, there are two languages of Chinese and English.
Re: Can anyone write assembly code to copy a string?
https://www.jianshu.com/p/940fe7005409
This is a business case for actual use. Using Memory Map to Develop High Performance Interprocess Message Communication Component I. Background In the development of project, it is unavoidable to communicate messages between modules or systems. At present, the popular message middleware includes Redis, RabbitMQ, Kafka, RocketMQ and so on. Among the above components, Redis performs well in terms of message queues, but not when it comes to publish/subscribe. A recent project using Redis publish/subscribe can only send out a few thousand messages per second, which is more than enough at the moment, but bottlenecks can be expected. III. Principles The problem is to use memory mapping to do with a machine under a variety of message communication, memory mapping is more suitable for the message queue, because the message can be persistent in the local, not read the next time in can also continue to read. Actual optimization results: The structure is 128 bytes and can process 1.8 million data per second, which is 1000 times faster.
This is Chinese, please ignore it:
这是一个实际使用的商业案例
使用内存映射开发高性能进程间消息通信组件
一、背景
项目开发中免不了各模块或系统之间进行消息通信,目前热门的消息中间件有Redis、RabbitMQ、Kafka、RocketMQ等等。以上几种组件中Redis在消息队列方面表现还可以,但是如果涉及发布订 阅功能,就不行了,最近项目就使用了redis的发布订阅,每秒只能发出几千条,虽然目前绰绰有余,但是瓶颈可以预期。
三,原理
Re: Can anyone write assembly code to copy a string?
Originally Posted by xiaoyao
https://www.jianshu.com/p/940fe7005409
This is a business case for actual use. Using Memory Map to Develop High Performance Interprocess Message Communication Component I. Background In the development of project, it is unavoidable to communicate messages between modules or systems. At present, the popular message middleware includes Redis, RabbitMQ, Kafka, RocketMQ and so on. Among the above components, Redis performs well in terms of message queues, but not when it comes to publish/subscribe. A recent project using Redis publish/subscribe can only send out a few thousand messages per second, which is more than enough at the moment, but bottlenecks can be expected. III. Principles The problem is to use memory mapping to do with a machine under a variety of message communication, memory mapping is more suitable for the message queue, because the message can be persistent in the local, not read the next time in can also continue to read. Actual optimization results: The structure is 128 bytes and can process 1.8 million data per second, which is 1000 times faster.
This is Chinese, please ignore it:
这是一个实际使用的商业案例
使用内存映射开发高性能进程间消息通信组件
一、背景
项目开发中免不了各模块或系统之间进行消息通信,目前热门的消息中间件有Redis、RabbitMQ、Kafka、RocketMQ等等。以上几种组件中Redis在消息队列方面表现还可以,但是如果涉及发布订 阅功能,就不行了,最近项目就使用了redis的发布订阅,每秒只能发出几千条,虽然目前绰绰有余,但是瓶颈可以预期。
三,原理
Re: Can anyone write assembly code to copy a string?
Originally Posted by dreammanor
Do you mean that you are using VB6 to develop high-performance communication components with millions of data per second?
This article was not written by me. The example represents that using memory mapping technology can improve the read and write speeds by several tens to hundreds of times, and at least several times. It is worth studying and implementing.
Just like reading all rows and columns of the query result of sqlite database, the common method is 10 fields and 1000 rows, which requires calling api 10,000 to 50,000 times. The good method only needs to return all data directly to the two-dimensional array.
You can ignore this Chinese:就像读取sqlite数据库查询结果所有行列一样,普通的方法就是10个字段,1000行,需要调用api一万到5万次,好的方法只需要一次,直接返回所有数据到二维数组。
Re: Can anyone write assembly code to copy a string?
The query example is flawed on several level.
For a 10 by 1000 recordset manually looping it will take less than a second to execute so lets suppose we are dealing with a recordset of 10 columns by 1 mil. rows so that looping vs GetRows can have noticable difference.
It will most likely be like 5 seconds vs 1 second for the GetRows call. And then you have the actual database query that takes *minutes* to execute. . . So not very good optimization effort overall.
That's why everyone is optimizing the db queries where one can get orders of magnitude speed ups, not the recordset fields access.
It is almost the same case with shared-memory. COM already does it, why bother dealing with raw pointers and risking AV if the moon does not align very well every once in a while.
Re: Can anyone write assembly code to copy a string?
Originally Posted by wqweto
The query example is flawed on several level.
For a 10 by 1000 recordset manually looping it will take less than a second to execute so lets suppose we are dealing with a recordset of 10 columns by 1 mil. rows so that looping vs GetRows can have noticable difference.
It will most likely be like 5 seconds vs 1 second for the GetRows call. And then you have the actual database query that takes *minutes* to execute. . . So not very good optimization effort overall.
That's why everyone is optimizing the db queries where one can get orders of magnitude speed ups, not the recordset fields access.
It is almost the same case with shared-memory. COM already does it, why bother dealing with raw pointers and risking AV if the moon does not align very well every once in a while.
cheers,
</wqw>
this asm code can run in "e" LANGUAGE,BUT CAN'T RUN IN VB6,CAN YOU HELP ME?
Code:
.版本 2
' mov esi,[ebp+8h]
' test esi,esi
' je L1
' mov edi,[ebp+0ch]
' test edi,edi
' je L1
' sub esi,4
' mov eax,[esi]
' add eax,4
' mov ebx,4
' div ebx
' mov ecx,eax
' rep movsd
' mov ecx,edx
' rep movsb
' L1:
I WANT TO COPY bstr type BYTE USE ASMCODE,HOW TO DO?
tools (masm.exe Microsoft Macro Assembler ,version9,2008-10-1),how to write asm code use this tool?
Public Function CopyStrToMemory(FromStrPtr As Long, CopyToStrPtr As Long) AS LONG
'#ASM mov eax, DWORD PTR _Addr$[esp]
'#ASM mov eax, [eax];从指针处读取
END Function
Last edited by xiaoyao; Feb 17th, 2020 at 05:49 PM.
Re: Can anyone write assembly code to copy a string?
I found a Complier tools,(support c++,asm code)
You can directly insert asm code, or c ++ code, inside a vb function.
it's a plug-in VB-ADDIN, is an ACTIVEX. DLL (COM component)There are two compilers in the resource:
BCC32.EXE (1.27M)
Borland C/C + + Complier, 1988-2005, file version 5.8, product version 10.0
ML.EXE (353K), estimated to be an assembler ASM compiler
Probably 2008, version 9.0.30729, full name: Microsoft Macro Assembler
[New alert] VB embedded assembly + Standard Dll plugin open source-page 7-Tech World-VB Fan Paradise (VB good)-Powered by Discuz! http://www.vbgood.com/article-8858-7.html
The following is in Chinese, please ignore it.
我找到了一个可以同时写c函数和汇编代码的编绎插件是VB-ADDIN,是一个ACTIVEX.DLL(COM组件)
资源里面有2个编绎器:
BCC32.EXE (1.27M)
Borland C/C++ Complier,1988-2005年,文件版本5.8,产品版本10.0