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.

DarkBASIC Professional Discussion / Is this accurate?

Author
Message
C0wbox
20
Years of Service
User Offline
Joined: 6th Jun 2006
Location: 0,50,-150
Posted: 26th Oct 2010 00:39

I just thought I'd work out how big an array was,
((((8+32+32)*512*255)/8)/1024)/1024

Simple question:
Will the array CURRENT actually be ~1.12mb or more/less?

IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 26th Oct 2010 00:54 Edited at: 26th Oct 2010 00:55
I'll try and make this as accurate as I can, but know now that it isn't going to be exact - just a minimum figure of memory used.

The calculation you should carry out is:
(SizeOfType+4)*(Dimension1+1)*(Dimension2+1)+54

The size of a type for a UDT, is that each element is 4 bytes, except for those taking 8 bytes each (double float & double integer). Your UDT is 12 bytes in size.

(12+4)*(512+1)*(255+1)+54
= 16*513*256+56
= 2101304 bytes
= ~2mb

Even that's not quite right though, because the minimum allocation size for windows OS's varies between either 16 bytes or 32 bytes (so that '12' isn't quite right), plus there's overhead for the memory management system itself, which I couldn't even begin to guess at.

Utility plug-ins (26-JUL-2010)
I'm applying terms of use that require you to wear a red nose and honk a horn whenever you use the Internet
C0wbox
20
Years of Service
User Offline
Joined: 6th Jun 2006
Location: 0,50,-150
Posted: 26th Oct 2010 01:27 Edited at: 26th Oct 2010 01:30
O wow, I didn't think it would work like that.
I was going on the whole, 8 bits for .TYP, 32 bits for .X and 32 for .Y then multiplying it all up and down.

Does a variable defined as byte actually only take up 256 bits? Or is this a false perception?


As well as all that:
Is the array CURRENT stored in the RAM or somewhere else? (That may seem like a stupid question but I've been wrong before. )
Is a ~2mb array cause for concern? - Or are the only causes for concern the usage of such arrays?

revenant chaos
DBPro Master
19
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Robbinsdale, MN
Posted: 26th Oct 2010 08:43
Quote: "The size of a type for a UDT, is that each element is 4 bytes, except for those taking 8 bytes each (double float & double integer). Your UDT is 12 bytes in size"

Does that also apply to standard arrays, or just UDT arrays? It doesn't make any sense to allow bytes in a UDT if they will just turn out to consume 4 bytes anyway.
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 26th Oct 2010 22:07
They used to take up just the space needed to store the value, but it's actually faster to read/write to them if they are stored aligned on a 4 byte boundary - Most other languages do something similar, but a little more complex.

If you have my plug-ins, you can test it yourself:


Quote: "Does a variable defined as byte actually only take up 256 bits?"

A byte will take up 4 bytes of space, but will only store a value of 0 to 255.

Quote: "Is the array CURRENT stored in the RAM or somewhere else?"

In RAM, unless the OS has paged it out to disk (which will only happen if you are very low on memory anyway).

Quote: "Is a ~2mb array cause for concern?"

Not at all - if you have 2GB of RAM in your system, that's less than 1000th of the memory, and you'll likely be using far more than that anyway just in the spaces used by your media.

Utility plug-ins (26-JUL-2010)
I'm applying terms of use that require you to wear a red nose and honk a horn whenever you use the Internet
C0wbox
20
Years of Service
User Offline
Joined: 6th Jun 2006
Location: 0,50,-150
Posted: 27th Oct 2010 00:15
Awesome !

Thanks.

Login to post a reply

Server time is: 2026-07-22 04:38:01
Your offset time is: 2026-07-22 04:38:01