Page 1 of 1
Cannot successfully run this test for packer library
Posted: Mon Feb 12, 2007 3:53 pm
by SkyManager
I cannot successfully run this test for testing the packer functions.
I am running it with PC3.94 on Red Hat 9
The pack result is always ZERO.
Code: Select all
OpenConsole()
PrintN("")
src.s = "This is a testing line string."
srcLen = Len(src)
*srcMem = AllocateMemory(srcLen)
*destMem= AllocateMemory(srcLen+100)
PokeS(*srcMem, src)
res = PackMemory(*srcMem, *destMem, srcLen)
PrintN(src)
PrintN("Pack Result = " + Str(res))
If (res)
res = UnpackMemory(*srcMem, *destMem)
PrintN("UnPack Result = " + Str(res))
EndIf
PrintN(PeekS(*destMem, srcLen))
FreeMemory(*srcMem)
FreeMemory(*destMem)
CloseConsole()
End
Pls help :roll:
Posted: Mon Feb 12, 2007 4:44 pm
by Clutch
I can't say definitively, but I think the problem may be a minimum length issue. In testing your code using ASCII strings comprised of random lower case [a...z] characters, the minimum length was 128 before it would work. Even so, it failed approximately three out of four times, and when it did succeed, the resulting packed length was ~130 bytes.
There is also an error in your code. The source parameter for UnpackMemory() is the packed memory. Change this:
Code: Select all
If (res)
res = UnpackMemory(*srcMem, *destMem)
PrintN("UnPack Result = " + Str(res))
EndIf
to this:
Code: Select all
If (res)
res = UnpackMemory(*destMem, *srcMem)
PrintN("UnPack Result = " + Str(res))
EndIf
This is what I used to test:
Code: Select all
OpenConsole()
PrintN("")
For i = 1 To 128
src.s + Mid("abcdefghijklmnopqrstuvwxyz", Random(25) + 1, 1) ;"This is a testing line string."
Next i
srcLen = Len(src)
*srcMem = AllocateMemory(srcLen + 1)
*destMem= AllocateMemory(srcLen+100)
PokeS(*srcMem, src)
res = PackMemory(*srcMem, *destMem, srcLen)
PrintN(src)
PrintN("Pack Result = " + Str(res))
If (res)
res = UnpackMemory(*destMem, *srcMem)
PrintN("UnPack Result = " + Str(res))
EndIf
PrintN(PeekS(*srcMem, srcLen))
FreeMemory(*srcMem)
FreeMemory(*destMem)
Input()
CloseConsole()
HTH,
Clutch
EDIT: Nevermind.. I just tried this with a single-character-length string and it worked. The resulting memory was 14 bytes in length, but it did work.
Posted: Tue Feb 13, 2007 12:33 am
by SkyManager
If the original string length is 128 and the resulting packed string length is 130, what does the packer do for packing
I supposed the packer is packing/compressing things but it is now adding more length.
Moreover, when I run your codes in PB4/Windows, it works about 60% trials.
But when testing in PB394/RedHat9, it works but hangs the whole IDE, I cannot even kill the PB thread. Very buggy

Posted: Tue Feb 13, 2007 12:46 am
by SkyManager
After more trials, I think the problem appears in your Random function.
Here is my modified
Code: Select all
OpenConsole()
PrintN("")
For i = 1 To 100
src.s + "(" + RSet(Str(i),3,"0") + ") This is a testing string. "
Next i
srcLen = Len(src)
*srcMem = AllocateMemory(srcLen + 1)
*destMem= AllocateMemory(srcLen+100)
PokeS(*srcMem, src)
res = PackMemory(*srcMem, *destMem, srcLen)
PrintN(src)
PrintN("Pack Result = " + Str(res))
If (res)
res = UnpackMemory(*destMem, *srcMem)
PrintN("UnPack Result = " + Str(res))
EndIf
PrintN(PeekS(*srcMem, srcLen))
FreeMemory(*srcMem)
FreeMemory(*destMem)
Input()
CloseConsole()
