Cannot successfully run this test for packer library

Linux specific forum
SkyManager
Enthusiast
Enthusiast
Posts: 339
Joined: Tue Jan 30, 2007 5:47 am
Location: Hong Kong

Cannot successfully run this test for packer library

Post 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:
Clutch
User
User
Posts: 52
Joined: Sun Nov 26, 2006 6:11 am
Location: South Florida

Post 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.
"Ahead one third... ahead two thirds... Full ahead flank
And out from the belly of the whale came a prophet, Amen"
SkyManager
Enthusiast
Enthusiast
Posts: 339
Joined: Tue Jan 30, 2007 5:47 am
Location: Hong Kong

Post 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 :evil:
SkyManager
Enthusiast
Enthusiast
Posts: 339
Joined: Tue Jan 30, 2007 5:47 am
Location: Hong Kong

Post 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()
:D
Post Reply