Types question - unused fields

Blitz3D Forums/Blitz3D Programming/Types question - unused fields

xmlspy(Posted 2007) [#1]
If I don't use a field in a type does it still suck a lot of memory?

Type mesh
field handle
field name$
End Type

m.mesh
m\handle = createcube()

Does the m\name$, if empty, still utilize the same amount of memory?


Matty(Posted 2007) [#2]
While I cannot say for sure - a string like m\name$ would take up as much memory as the string's length in bytes. So as they begin initialised as "" then it probably would take up 4 bytes for the length of the string and 0 bytes for "". (As a string in blitz uses 4bytes (integer value for length) plus 1 byte per character. If you had another field like m\value defined as an int or float then I would guess it still takes up 4 bytes as it has an initial value of zero although you hadn't assigned it that yourself.

I could be completely wrong but I think that is how it works.


Beaker(Posted 2007) [#3]
I think all fields take up at least 4 bytes (and as Matty says probably 5 bytes for strings).


Danny(Posted 2007) [#4]
Since we're talking bit and bytes here I don't think it's something you should worry about. Memory is cheap. And details like this will not affect you're game's performance.

Unless you have tens of thousands of those empty types - then it might be usefull comming up with something 'slightly' more effecient by seperating 'static' information (eg. name which is the SAME for each instance) and dynamic information (eg. mesh handle, which is unique for each instance). For example:

type mesh
field name.info
field handle
end type

type info
field name$
field description$
end type

This was you can have multiple mesh's 'sharing' or 'pointing' to the same 'static' information. And you'll only spend the 4 bytes for a pointer to the info Type. Whilst the name string itself can be 100's bytes or whatever, it is only allocated once.

d.


Beaker(Posted 2007) [#5]
Agree, generally memory shouldn't concern you too much. But, if your type objects get too large (can't remember at what size) there is a speed penalty as well. (I don't mean in number, but how many fields in one type.)