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?
How to get object overall size
How to get object overall size
ABCza on the old forum.
My GitHub.
My GitHub.
Re: How to get object overall size
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)
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)
Re: How to get object overall size
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!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)
ABCza on the old forum.
My GitHub.
My GitHub.
Re: How to get object overall size
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?VxE wrote:You can serialize AHK objects as JSON.
Last edited by cyruz on 20 Jan 2014, 12:26, edited 1 time in total.
ABCza on the old forum.
My GitHub.
My GitHub.
Re: How to get object overall size
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.
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.
Re: How to get object overall size
Yes I was hoping that! A ToBin() method would be a nice feature... Again, thank you for the info lexikoslexikos 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.
ABCza on the old forum.
My GitHub.
My GitHub.
Who is online
Users browsing this forum: doodles333, mikeyww and 273 guests