|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
memory leak ?i have the following code:
-------------------------- Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long) Private Sub Command1_Click() Dim a As String Dim b As String a = "abcdefghijklm" b = "123456" CopyMemory ByVal VarPtr(b), ByVal VarPtr(a), 4 'now both variables refer to the same string 'as can be seen by: Print a, StrPtr(a), b, StrPtr(b) 'what happens to the string "123456" ? 'does this cause a memory leak ? End Sub --------------------------
Show quote
Hide quote
"PC" <On***@pandora.be> wrote in message Yesnews:OqOmvofZFHA.3648@TK2MSFTNGP14.phx.gbl > i have the following code: > -------------------------- > Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" > (pDst As Any, pSrc As Any, ByVal ByteLen As Long) > > Private Sub Command1_Click() > Dim a As String > Dim b As String > a = "abcdefghijklm" > b = "123456" > CopyMemory ByVal VarPtr(b), ByVal VarPtr(a), 4 > 'now both variables refer to the same string > 'as can be seen by: > Print a, StrPtr(a), b, StrPtr(b) > 'what happens to the string "123456" ? > 'does this cause a memory leak ? > End Sub > -------------------------- -- Reply to the group so all can participate VB.Net: "Fool me once..." ok thanks Bob
now i have this: ------------------- Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long) Private Sub Command1_Click() Dim a As String Dim b As String Dim L As Long a = "abcdefghijklm" b = "123456" Print a, StrPtr(a), b, StrPtr(b) CopyMemory L, ByVal VarPtr(a), 4 CopyMemory ByVal VarPtr(a), ByVal VarPtr(b), 4 CopyMemory ByVal VarPtr(b), L, 4 'a and b are now swapped as seen by: Print a, StrPtr(a), b, StrPtr(b) 'would that cause a memory leak ? End Sub ------------------ "
Show quote
Hide quote
"PC" <On***@pandora.be> wrote in message I don't think so... what are you really trying to accomplish? news:u0vavxhZFHA.612@TK2MSFTNGP12.phx.gbl > ok thanks Bob > now i have this: > ------------------- > Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" > (pDst As Any, pSrc As Any, ByVal ByteLen As Long) > > Private Sub Command1_Click() > Dim a As String > Dim b As String > Dim L As Long > a = "abcdefghijklm" > b = "123456" > Print a, StrPtr(a), b, StrPtr(b) > CopyMemory L, ByVal VarPtr(a), 4 > CopyMemory ByVal VarPtr(a), ByVal VarPtr(b), 4 > CopyMemory ByVal VarPtr(b), L, 4 > 'a and b are now swapped as seen by: > Print a, StrPtr(a), b, StrPtr(b) > 'would that cause a memory leak ? > End Sub -- Reply to the group so all can participate VB.Net: "Fool me once..." >>what are you really trying to accomplish?<< nothing special really...just playing(right now i am trying to come to grips with savearray's) but it comes to my mind that it could be used as a fast swap routine and i just think of something: suppose i do something like: ----------------- Swap2Strs a, b Sub Swap2Strs(s1 As String, s2 As String) 'do something End Sub ----------------- then i suppose varptr(a) and varptr(b) get put on the stack now if there were a way to swap them on the stack would a and b then not be swapped just by leaving Sub Swap2Strs ? any idea's ? "PC" <On***@pandora.be> schrieb im Newsbeitrag See http://www.devx.com/vb2themax/Tip/18645news:%237bxTJoZFHA.580@TK2MSFTNGP15.phx.gbl... > Swap2Strs a, b > ... Don thanks for the link Don
but the idea is just to not do that the idea is getting my greedy hands directly on the stack maybe something like putting some machine codes in a byte array and somehow executing it (CallWindowProc it ?) something like: (pseudo assembler) put what is in stackpointer + somenumber in eax put what is in stackpointer + somenumber+4 in stackpointer + somenumber put what is in eax in stackpointer + somenumber if only i knew how Show quoteHide quote "Donald Lessau" <don.s***@xbeat.snip.net> wrote in message news:d7juvm$c2k$1@newsreader3.netcologne.de... > "PC" <On***@pandora.be> schrieb im Newsbeitrag > news:%237bxTJoZFHA.580@TK2MSFTNGP15.phx.gbl... > > Swap2Strs a, b > > ... > > See http://www.devx.com/vb2themax/Tip/18645 > > Don > "PC" <On***@pandora.be> schrieb im Newsbeitrag You can inject Assembly Snippets into VB code, you might get some ideasnews:ufZKZApZFHA.1404@TK2MSFTNGP09.phx.gbl... > ... > something like: (pseudo assembler) > put what is in stackpointer + somenumber in eax > put what is in stackpointer + somenumber+4 in stackpointer + somenumber > put what is in eax in stackpointer + somenumber > if only i knew how here: http://www.xbeat.net/vbspeed/c_ShiftLeft.htm#ShiftLeft04 |
|||||||||||||||||||||||