Dump an object to memory or save to file for later use.

OutputVar := ObjDump(ObjectOrPath , DumpToVar, Mode, Password)
Command  Example: ObjDump "C:\Temp\MyObject.dmp", obj
Function Example: size := ObjDump(obj, var)



The name of the variable in which to store the size of dumped object.


The object to be dumped to memory.
To save the object to a file this parameter must be the file path and DumpToVar parameter the object, see Examples.

DumpToVar (optional)

The name of the variable in which to store the dumped memory. When this parameter is omitted only the size will be returned.
When saving the object to a file this parameter will be the obect and ObjOrPath the filepath.

Mode (optional)

This parameter has effect on values of type string only and determines whether the dumped object will be zipped.
Supported modes are 0 (default), 1 (dump complete memory), 2 (default + compression), 3 (dump complete memory and compress).
When Mode is 2 or 3, dumped object will be compressed and you can use a password to encrypt the data.
When Mode is 1 or 3, complete memory of string values is saved using obj.GetCapacity(key). Otherwise only the actual string including terminating character is saved.

Password (optional)

When Mode parameter is omitted or 0 or 1, this parameter can be a passwords to use for dumped object.

General Remarks

Only standard objects and arrays are supported, ComObject, RegExMatchObject, FileObject, Func and DynaCall objects are not supported.
Struct object can be dumped but ObjLoad will restore a normal object instead of a Struct object.
The "base" reference is not saved in ObjLoad and is not restored.
By default (Mode = 0) and Mode = 1 the dumped object is compressed and a password can be used to encrypt the dumped object.




; Create a simple object
obj := {key:"value",1:"test",2:10}

; Dump an object to variable.
sz := ObjDump(obj, var)

; Restore an object from variable
obj := ObjLoad(&var)

; Dump an object to file
sz := ObjDump(A_ScriptDir "\MyDump.bin", obj)

; Restore an object from file
obj := ObjLoad(A_ScriptDir "\MyDump.bin")

; Get the dump size of an object 
MsgBox % ObjDump(obj)