[Lib] ObjDump / ObjLoad - Object Backup

Post your working scripts, libraries and tools
HotKeyIt
Posts: 1448
Joined: 29 Sep 2013, 18:35
Contact:

[Lib] ObjDump / ObjLoad - Object Backup

18 May 2014, 05:48

Note!
  • Only standard objects are supported, ComObject, RegExMatchObject, FileObject, Func and DynaCall (AutoHotkey_H only) objects are not supported.
  • Struct (AutoHotkey_H only) object can be dumped but ObjLoad will restore a normal object instead of Struct object.
  • When value is of type string or raw data, ObjDump will dump only the string by default and always for keys, so StrPut(key)*(A_IsUnicode?2:1) is used. Additional parameter DumpBuffer can be used to force dumping obj.GetCapacity(value) instead of StrPut(value)*(A_IsUnicode?2:1) for values.
  • Numbers consume only required bytes using NumSize/NumType.

A small drawback is that resulting file might get quite big, especially when using DumpBuffer=true.

Dump object to variable/memory:
size := ObjDump(Object,Variable,DumpBuffer)
Load object from variable/memory:
Obj := ObjLoad(Address)

Dump object to file:
size := ObjDump(FilePath,Object,DumpBuffer)
Load object from file:
Obj := ObjLoad(FilePath)


AutoHotkey v1

AutoHotkey v2


UPDATE:
    *25.02.2016
  • Fix ObjLoad bug.
  • ObjDump and ObjLoad can now handle object reference to itself or another object within dumped object.
    *02.11.2015
  • Fix saving binary memory of key (use obj.GetAddress(k) instead of &v)
    *20.08.2015
  • Include size of dumped object for simplified use
    Note wrote:New ObjLoad() function is not compatible to the old functions and cannot load a file dumped with old ObjDump function.
    You can rename the old ObjLoad function to ObjLoad2 and run this with new ObjDump function:
    ObjDump(ObjLoad2(File),File)
  • 20.05.2014
  • Implemented obj-64 -> file -> obj-32 and the other way round.
  • Use only the required memory for numbers.
  • Additional parameter DumpBuffer, when true obj.GetCapacity(key) is used else StrPut(value)*(A_IsUnicode?2:1)
  • 18.05.2014
  • Fixed writing large objects

Old_Versions
User avatar
cyruz
Posts: 243
Joined: 30 Sep 2013, 13:31

Re: [Lib] ObjDump / ObjLoad - Object Backup

18 May 2014, 10:01

This is seriously good stuff. I asked for this as a builtin some time ago... Thank you for your work!
ABCza on the old forum.
My GitHub.
Guest10
Posts: 578
Joined: 01 Oct 2013, 02:50

Re: [Lib] ObjDump / ObjLoad - Object Backup

18 May 2014, 16:28

this script is way over my head. any examples a newbie can use this? :geek:
HotKeyIt
Posts: 1448
Joined: 29 Sep 2013, 18:35
Contact:

Re: [Lib] ObjDump / ObjLoad - Object Backup

18 May 2014, 16:39

Save_Load_Object_to_file

Save_Load_Object_to_variable
arcticir
Posts: 466
Joined: 17 Nov 2013, 11:32

Re: [Lib] ObjDump / ObjLoad - Object Backup

19 May 2014, 05:23

Interesting attempt, but obviously failed.

Code: [Select all] [Download] (Script.ahk)GeSHi © Codebox Plus

ObjDump(A_ScriptDir "\1.b",AhkDllThread())
AhkThread := ObjLoad(A_ScriptDir "\1.b")
AhkThread.ahktextdll("MsgBox,Test")
MsgBox
HotKeyIt
Posts: 1448
Joined: 29 Sep 2013, 18:35
Contact:

Re: [Lib] ObjDump / ObjLoad - Object Backup

19 May 2014, 05:42

There are 2 things why this would not work:
- when ObjDump finishes the reference to the AhkDllThread object is deleted and MemoryFreeLibrary is called so there is no code anymore.
- Only standard objects are supported, RegEx, DynaCall and Struct objects are not standard objects and cannot be dumped/loaded properly.
strobo
Posts: 125
Joined: 30 Sep 2013, 15:24

Re: [Lib] ObjDump / ObjLoad - Object Backup

19 May 2014, 09:28

Nice Lib.
Time (encode, decode) and Space benchmark vs JSON implementations (and/or other (de)serializations) would be interesting.
HotKeyIt
Posts: 1448
Joined: 29 Sep 2013, 18:35
Contact:

Re: [Lib] ObjDump / ObjLoad - Object Backup

19 May 2014, 12:04

Thanks ;)

Time to decode encode depends on size of the object, in avarage ObjDump/ObjLoad will be faster.
I have written ObjDump to support high speed dump for huge objects and dumping any content, so even raw data is supported.

My tests shown, the larger the object, the faster ObjLoad and ObjDump would be, for example even here ObjDump is faster:

Code: [Select all] [Expand] [Download] (Script.ahk)GeSHi © Codebox Plus

HotKeyIt
Posts: 1448
Joined: 29 Sep 2013, 18:35
Contact:

Re: [Lib] ObjDump / ObjLoad - Object Backup

20 May 2014, 16:14

Update:
  • Implemented obj-64 -> file -> obj-32 and the other way round.
  • Use only the required memory for numbers(char,short,integer,int64,double).
  • Changed to consume only one byte for data type.
  • Additional parameter DumpBuffer, when 0/false (default) StrPut(value)*(A_IsUnicode?2:1) is used, eslse obj.GetCapacity(key) is used to dump all data for values.

Note wrote:New ObjLoad() function is not compatible to the old functions and cannot load a file dumped with old ObjDump function.
You can rename the old ObjLoad function to ObjLoad2 and run this with new ObjDump function:
ObjDump(ObjLoad2(File),File)
User avatar
joedf
Posts: 5739
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada, Quebec
Contact:

Re: [Lib] ObjDump / ObjLoad - Object Backup

20 May 2014, 20:44

Finally! I wanted this for quite a while, thanks HotkeyIt ;)
arcticir
Posts: 466
Joined: 17 Nov 2013, 11:32

Re: [Lib] ObjDump / ObjLoad - Object Backup

15 Aug 2014, 03:49

hi HotKeyIt

I try to use this function to pass objects between processes,Use Help on OnMessage examples:
The script stagnation, where the reason for this?

Receive

Code: [Select all] [Download] (Script.ahk)GeSHi © Codebox Plus

#SingleInstance
OnMessage(0x4a, "Receive_WM_COPYDATA") ; 0x4a 为 WM_COPYDATA
WinSetTitle, ahk_id %A_ScriptHwnd%, ,Receive
return

Receive_WM_COPYDATA(wParam, lParam)
{
ToolTip,Receive_WM_COPYDATA
j := ObjLoad(lParam,wParam)
MsgBox % j.A
}


Code: [Select all] [Expand] [Download] (Script.ahk)GeSHi © Codebox Plus

HotKeyIt
Posts: 1448
Joined: 29 Sep 2013, 18:35
Contact:

Re: [Lib] ObjDump / ObjLoad - Object Backup

15 Aug 2014, 05:25

Enjoy ;)
DynaRun()

Code: [Select all] [Expand] [Download] (WM_COPYOBJECT.ahk)GeSHi © Codebox Plus

arcticir
Posts: 466
Joined: 17 Nov 2013, 11:32

Re: [Lib] ObjDump / ObjLoad - Object Backup

15 Aug 2014, 08:59

Thanks. :D

Incidentally:
erratic Crash disappeared.
expect H v1.1.15

----------------------------
I try to use an object to pass parameters, but why not correct?

Code: [Select all] [Expand] [Download] (Script.ahk)GeSHi © Codebox Plus

arcticir
Posts: 466
Joined: 17 Nov 2013, 11:32

Re: [Lib] ObjDump / ObjLoad - Object Backup

15 Aug 2014, 16:30

我稍加修改,使之便于阅读,也许会提升些许效率。
I slightly modified to make it easier to read, and perhaps will increase a little efficiency.


Code: [Select all] [Expand] [Download] (Script.ahk)GeSHi © Codebox Plus



Code: [Select all] [Expand] [Download] (Script.ahk)GeSHi © Codebox Plus




In this example, about 500 milliseconds faster.

Code: [Select all] [Expand] [Download] (Script.ahk)GeSHi © Codebox Plus

HotKeyIt
Posts: 1448
Joined: 29 Sep 2013, 18:35
Contact:

Re: [Lib] ObjDump / ObjLoad - Object Backup

16 Aug 2014, 08:11

arcticir wrote:I try to use an object to pass parameters, but why not correct?
Following DynaRun() versions will automatically convert obj to hex and create global A_Argv in new process containing a copy of the object:

DynaRun_for_AutoHotkey_v1
DynaRun_for_AutoHotkey_v2
User avatar
nnnik
Posts: 2125
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: [Lib] ObjDump / ObjLoad - Object Backup

16 Aug 2014, 08:27

HotKeyIt these spoilers make it impossible to read anything.
So I changed them.
Recommends AHK Studio
HotKeyIt
Posts: 1448
Joined: 29 Sep 2013, 18:35
Contact:

Re: [Lib] ObjDump / ObjLoad - Object Backup

16 Aug 2014, 09:23

My fault, thanks nnnik :)

For reference: ObjToHex() and HexToObj().
AutoHotkey_v1
AutoHotkey_v2
arcticir
Posts: 466
Joined: 17 Nov 2013, 11:32

Re: [Lib] ObjDump / ObjLoad - Object Backup

16 Aug 2014, 09:28

Is it necessary?

Code: [Select all] [Download] (Script.ahk)GeSHi © Codebox Plus

Run, % AhkPath pf """ " (IsObject(pr) ? "": pr),,UseErrorLevel HIDE, P



In addition, Is it possible also add this to BinRun, relatively speaking, I am more like BinRun.
Run BinRun Mouse does not appear funnel. ;)
HotKeyIt
Posts: 1448
Joined: 29 Sep 2013, 18:35
Contact:

Re: [Lib] ObjDump / ObjLoad - Object Backup

16 Aug 2014, 12:02

arcticir wrote:Is it necessary?

Code: [Select all] [Download] (Script.ahk)GeSHi © Codebox Plus

Run, % AhkPath pf """ " (IsObject(pr) ? "": pr),,UseErrorLevel HIDE, P
No.
In addition, Is it possible also add this to BinRun, relatively speaking, I am more like BinRun.

Sure :)
BinRun_for_AutoHotkey_v1
arcticir
Posts: 466
Joined: 17 Nov 2013, 11:32

Re: [Lib] ObjDump / ObjLoad - Object Backup

16 Aug 2014, 12:54

Thanks.

Can I request a more concise BinRun It?
only for AHK_H,I have never used other versions loaded BinRun
only load AHKH. EXE, I only used to load AHKH.EXE, not loaded over other software
and will AHK. EXE stored in the variable, so that the next call.

Return to “Scripts and Functions”

Who is online

Users browsing this forum: No registered users and 29 guests