Best way to do multiple types in Blitzmax

BlitzMax Forums/BlitzMax Beginners Area/Best way to do multiple types in Blitzmax

okee(Posted 2011) [#1]
Whats the best way to manage a lot of data with Types
i.e. I might have 100 scenes and within each scene is 1 to 5 items
Blitzplus (i think) used to automatically manage multiple instances
of a type but from searching it seems Blitzmax doesn't
Is TList the answer ?

Type TScene
     Field SceneNo:Int
     Field Description:String
     Field Item: TItem
End Type

Type TItem
     Field ItemNo:Int
     Field Description:String
End Type



BladeRunner(Posted 2011) [#2]
It is.


GfK(Posted 2011) [#3]
Doesn't have to be a TList. You can use a TMap, or an Array. Each has its own advantages and disadvantages.

TList: Objects are stored in the order they were added (using ListAddLast/AddFirst). Not indexed. Lists have a ValueAtIndex method but this iterates through all items until it reaches the requested index, so can be slow on large lists.

TMap: Objects are stored in key/value pairs. Very fast retrieval but each key must be unique (otherwise existing data gets replaced). Stored in alphanumerical order by key.

Array: Fast retrieval of data by index. Not the best option where you want to add/remove/manipulate objects.


Who was John Galt?(Posted 2011) [#4]
To emulate the old B+ way of things, use a TList.


okee(Posted 2011) [#5]
Thanks chaps, I'll go the Lists route


H&K(Posted 2011) [#6]
Make the List a Global member of the type
So that the following would all give access and good code completion in BLIDE

AType.list
AnInstance.list

(And When relevent)
Self.list


Who was John Galt?(Posted 2011) [#7]
Yep, stick:

Global List:Tlist

Method New()
    List.addlast(self)
end method


With the use of one global within the type and one method, you can emulate the single autolist for each type like in previous blitz. New instances will be added to the list as New() is automatically called when an instance is created.


H&K(Posted 2011) [#8]
Hummmm

Ok would you not also need a remove from list somewhere?
The GC will clean the memory if there are no more references to an instance,
what it will not do is clean if there is only one reference left, that in the typelist.
So when ever you want to use a new instance just once, because you are auto adding it to the list, it needs to be removed.


(Grey and ohers had a 100+ thread about how this is normally the behaviour you want, but could it be overwritten so if the only reference was on the tlist then the GC cleans it)

Last edited 2011


Who was John Galt?(Posted 2011) [#9]
I'm not of the opinion these posed 'ummm' questions belittle those they are directed at as designed to. More a negative reflection on the poster.

But as you know, you are correct.


H&K(Posted 2011) [#10]
I dont design to belittle at all.

I tend to use Humm when Im not sure

Edit, In fact just did a search and Humm is used 55 times on these boards, (alot by me), and is used in the most;

To indicate reflection on the question
To suggest a course the previous postie might consider, because they have more knowledgeable of the issue then the current postie.

It seems to be generally used when a question is being raised about an answer where clarification is asked for, because the person saying Humm, thinks they dont know as much as the person they are asking.

Last edited 2011

Last edited 2011


Who was John Galt?(Posted 2011) [#11]
I'll take your word on that, but you may wish to consider how it is commonly used on the internet.

*EDIT* That was posted before the addition.

If it is mostly used by you on this board, that does not necessarily indicate common usage. Anyway, carry on regardless.

Last edited 2011


H&K(Posted 2011) [#12]
I'll take your word on that, but you may wish to consider how it is commonly used on the internet.
No