How to get object overall size

Get help with using AutoHotkey and its commands and hotkeys
User avatar
cyruz
Posts: 299
Joined: 30 Sep 2013, 13:31

How to get object overall size

16 Jan 2014, 13:38

Hi guys,
if I have an object I can find the size of the fields calling Object.GetCapacity(key), but how to find the overall size of the object itself? Is it safe to assume that the overall size is the sum of all fields size?
ABCza on the old forum.
My GitHub.
lexikos
Posts: 7088
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: How to get object overall size

17 Jan 2014, 03:17

Why would you want to do that?

The overall memory usage would be the sum of:
- the capacity of each string field
- the size of each string key (including null-terminator)
- the capacity of the object multiplied by A_PtrSize=4 ? 16 : 24
- the size of the object's "root" structure - A_PtrSize*8
- overhead for each of the above memory allocations (depends on the OS and the size of the allocation)
User avatar
cyruz
Posts: 299
Joined: 30 Sep 2013, 13:31

Re: How to get object overall size

17 Jan 2014, 08:05

lexikos wrote:Why would you want to do that?

The overall memory usage would be the sum of:
- the capacity of each string field
- the size of each string key (including null-terminator)
- the capacity of the object multiplied by A_PtrSize=4 ? 16 : 24
- the size of the object's "root" structure - A_PtrSize*8
- overhead for each of the above memory allocations (depends on the OS and the size of the allocation)
I was trying to understand if an object can be serialized in binary and stored, but looks like this is not possible; I guess that they are not allocated sequentially right? Anyway nice info!
ABCza on the old forum.
My GitHub.
User avatar
VxE
Posts: 44
Joined: 30 Sep 2013, 10:35
Location: Simi Valley, CA

Re: How to get object overall size

18 Jan 2014, 03:09

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

Re: How to get object overall size

18 Jan 2014, 06:28

Yes, that's what I'm doing now. I was just curious. @lexikos, is this a feature that you have in your "todo list" for v2?
Last edited by cyruz on 20 Jan 2014, 12:26, edited 1 time in total.
ABCza on the old forum.
My GitHub.
lexikos
Posts: 7088
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: How to get object overall size

20 Jan 2014, 03:12

No, v2 is not about new features - see http://ahkscript.org/v2/

There's no reason you couldn't use a binary data format to serialize an object. You'd have to go through the same sort of process as when you serialize to JSON, but choose a binary format instead of text. But I suppose rather than serializing the object, you were actually hoping to just copy the object data in one go. That won't work because as you guessed, an object isn't just one continuous block of memory.
User avatar
cyruz
Posts: 299
Joined: 30 Sep 2013, 13:31

Re: How to get object overall size

20 Jan 2014, 12:32

lexikos wrote:No, v2 is not about new features - see http://ahkscript.org/v2/

There's no reason you couldn't use a binary data format to serialize an object. You'd have to go through the same sort of process as when you serialize to JSON, but choose a binary format instead of text. But I suppose rather than serializing the object, you were actually hoping to just copy the object data in one go. That won't work because as you guessed, an object isn't just one continuous block of memory.
Yes I was hoping that! A ToBin() method would be a nice feature... Again, thank you for the info lexikos :)
ABCza on the old forum.
My GitHub.

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], c7aesa7r, Google [Bot], kunkel321, mikeyww and 42 guests