PackMemory x64 differs on x86

Just starting out? Need help? Post your questions and find answers here.
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

PackMemory x64 differs on x86

Post by Thunder93 »

Hi folks,

Can someone tell me if I'm doing something wrong...?, is it normal to be seeing PackMemory results with PureBasic x86 being different from PackMemory results with PureBasic x64 .. on the same unaltered file?

Code: Select all

newSize.l = PackMemory(mem1, mem2, Size,9)
x64 newSize = 88
x86 newSize = 70


Regards,
Thunder93
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: PackMemory x64 differs on x86

Post by ts-soft »

x64 use briefLZ and x86 use jCalg1

greetings
Thomas

/edit
you can use this for both:

Code: Select all

; Autor: Thomas (ts-soft) Schulz
; PB-Version: 4.xx
; OS: windows/linux

CompilerSelect #PB_Compiler_OS
  CompilerCase #PB_OS_Linux
    ImportC #PB_Compiler_Home + "purelibraries/linux/libraries/zlib.a"
  CompilerCase #PB_OS_Windows
    ImportC "zlib.lib"
CompilerEndSelect
  compress2(*dest, *destLen, *source, sourceLen, level)
  uncompress(*dest, *destLen, *source, sourceLen)
EndImport

Procedure zipPackMemory(*source, sourceLen = #PB_Default, level = #PB_Default)
  Protected *dest, destLen
  
  If level < #PB_Default Or level > 9 : level = #PB_Default : EndIf
  If *source
    If sourceLen = #PB_Default : sourceLen = MemorySize(*source) : EndIf
    destLen = sourceLen + 13 + (Int(sourceLen / 100))
    *dest = AllocateMemory(destLen)
    If *dest
      If Not compress2(*dest, @destLen, *source, sourceLen, level)
        *dest = ReAllocateMemory(*dest, destLen)
        ProcedureReturn *dest
      EndIf
    EndIf
  EndIf
EndProcedure

Procedure zipUnpackMemory(*source, *dest)
  Protected sourceLen = MemorySize(*source)
  Protected destLen = MemorySize(*dest)

  If Not uncompress(*dest, @destLen, *source, sourceLen)
    ProcedureReturn destLen
  EndIf
EndProcedure
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: PackMemory x64 differs on x86

Post by Thunder93 »

Thanks Thomas,

I remember being told this before, ... I like jCalg1 better, does better compression than the other one.
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: PackMemory x64 differs on x86

Post by ts-soft »

Thunder93 wrote:I like jCalg1 better, does better compression than the other one.
but can't pack all files like png, iso and so on, to many errors. I use mostly zip or for fast compress briefLZ
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Re: PackMemory x64 differs on x86

Post by DoubleDutch »

ts-soft: Thanks, nice routines that will be very handy. :)
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: PackMemory x64 differs on x86

Post by Thunder93 »

Thanks ts-soft for sharing!

For the current project I'm looking to use jCalg1, for a few different reasons. But your code will surely be useful enough in the future!



Regards,
Thunder93
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
jamirokwai
Enthusiast
Enthusiast
Posts: 796
Joined: Tue May 20, 2008 2:12 am
Location: Cologne, Germany
Contact:

Re: PackMemory x64 differs on x86

Post by jamirokwai »

ts-soft wrote:x64 use briefLZ and x86 use jCalg1

greetings
Thomas

/edit
you can use this for both:

Code: Select all

; Autor: Thomas (ts-soft) Schulz
; PB-Version: 4.xx
; OS: windows/linux/macos

CompilerSelect #PB_Compiler_OS
  CompilerCase #PB_OS_Linux
    ImportC #PB_Compiler_Home + "purelibraries/linux/libraries/zlib.a"
 CompilerCase #PB_OS_MacOS
  ImportC "/usr/lib/libz.dylib"
  CompilerCase #PB_OS_Windows
    ImportC "zlib.lib"
CompilerEndSelect
  compress2(*dest, *destLen, *source, sourceLen, level)
  uncompress(*dest, *destLen, *source, sourceLen)
EndImport

Procedure zipPackMemory(*source, sourceLen = #PB_Default, level = #PB_Default)
  Protected *dest, destLen
  
  If level < #PB_Default Or level > 9 : level = #PB_Default : EndIf
  If *source
    If sourceLen = #PB_Default : sourceLen = MemorySize(*source) : EndIf
    destLen = sourceLen + 13 + (Int(sourceLen / 100))
    *dest = AllocateMemory(destLen)
    If *dest
      If Not compress2(*dest, @destLen, *source, sourceLen, level)
        *dest = ReAllocateMemory(*dest, destLen)
        ProcedureReturn *dest
      EndIf
    EndIf
  EndIf
EndProcedure

Procedure zipUnpackMemory(*source, *dest)
  Protected sourceLen = MemorySize(*source)
  Protected destLen = MemorySize(*dest)

  If Not uncompress(*dest, @destLen, *source, sourceLen)
    ProcedureReturn destLen
  EndIf
EndProcedure
Hi there,

I added 2 lines for MacOS X-Support. Works great on PB 4.40b5 and PB 4.31 Intel :)
I will use these routines for my projects... I think on Mac OS, the file "/usr/lib/libz.dylib" is installed on default. But I don't know if it is save to rely on the existance. Maybe it's better to put a copy into the app-bundle also?!
Regards,
JamiroKwai
Post Reply