Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / [SOLVED] Types & Arrays Memory Usage

Author
Message
Nieb
9
Years of Service
User Offline
Joined: 13th May 2014
Location: Lurking
Posted: 14th Jul 2018 15:30 Edited at: 14th Jul 2018 16:54
Ran into an oddity with memory usage.

Blarg AS INTEGER[4096,4096]
32 bits * 4096 * 4096 = 536,870,912 bits = 67.108864 MB
I would expect this to use about 67 MB of memory. Upon testing, it does indeed use about 67 MB of memory.


Next, I would expect these to use roughly the same amount of memory:

Multiple vars example:


Type example:


The first example uses 348 MB or memory, the expected amount.
However, the second example uses 1138 MB of memory, about 3.27 times the amount of memory.

Where is all the overhead coming from?
Am I doing something wrong?

The author of this post has marked a post as an answer.

Go to answer

Nieb
9
Years of Service
User Offline
Joined: 13th May 2014
Location: Lurking
Posted: 14th Jul 2018 15:44 Edited at: 20th Jul 2018 18:07
Upon further testing, this produces the expected amount of memory use:



Weird. I would expect an Array of Vars & a Var of Arrays to be the same.
Richard_6
7
Years of Service
User Offline
Joined: 3rd Feb 2017
Location:
Posted: 15th Jul 2018 14:02
Interesting tests, Nieb. If you're in the mood, you could test global types vs passing types by ref. I noticed in the past that passing large objects as argument was consuming a lot of processing. I have no scientific evidence though.
Phaelax
DBPro Master
20
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 16th Jul 2018 04:07
This post has been marked by the post author as the answer.
There must be additional overhead for a UDT. When the UDT contains all the arrays, you're still only using a single UDT. When you make an array of UDTs, that overhead is multiplied by the size of the array, hence the much larger memory usage. If a single UDT uses an additional 12 bytes of memory, then compound that by 4096*4096.

I don't know the exact overhead or how UDTs are stored in ram, but your test results make sense if you think about it.

Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds

Login to post a reply

Server time is: 2024-03-29 11:56:25
Your offset time is: 2024-03-29 11:56:25