• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

[ SOLVED ] Data Structures

C

CedSharp

Guest
I have a complex structure for storing information.
Very briefly, it looks as follow:
Code:
/*
    _collection( ... ) will generate a queue with each argument as a value.
    _message( text ) will generate a 2x1 grid, first position containing an enum value, second a string.
    _dialog( name, collection ) will create a 2x1 grid with the 2 parameters.
    _assign_dialog( dialog ) will append the dialog to the queue of the current object created in create event.
*/

var dialog = _dialog( "My dialog",
    _collection(
        _message( "first message" ),
        _message( "second message" ),
        _message( "third message" )
    )
);

_assign_dialog( dialog );
It is more complex than that, but the above shows my point.
I would like to call one single script to get rid of all the data structures, recursively, inside the dialog variable.
So basically everything but the ds_queue in which _assign_dialog() appends to should be destroyed.

Does gamemaker support destroying and freeing memory for all data structures inside a data-structure?
For example, if I call ds_grid_destroy( dialog ), will it also free all the underlying grids and queues ?
Or do I have to recursively call destroy and clear on each of those myself?

Thanks.
 
C

CedSharp

Guest
In this case, you have to free the underlying structures yourself recursively.
Thanks for your answer. That means lazy me will have to implement a complex system to free my complex system haha, what a load of baloney.
 

FrostyCat

Redemption Seeker
Instead of using queues and grids, you could have used lists and maps. There are marking functions that will allow you to free just the top structure and make everything under it follow. Look up ds_map_add_map(), ds_map_add_list(), ds_list_mark_as_map() and ds_list_mark_as_list().
 
C

CedSharp

Guest
Instead of using queues and grids, you could have used lists and maps. There are marking functions that will allow you to free just the top structure and make everything under it follow. Look up ds_map_add_map(), ds_map_add_list(), ds_list_mark_as_map() and ds_list_mark_as_list().
In this case the problem I have is that the structure I'm generating can get quite big, and I need to go read/modify values often.
I use mainly grids to save memory ( a grid is fixed in size ) and queues when I need to save the order.

If I use lists, then reading/writing in the list isn't very effective, and it takes more memory because the resources aren't grouped together in memory ( the very nature of a list ).

And I don't like using maps because they use strings, which again, are a lot more
memory beasts compared to using an index, which is saved in an enum, so usage-side,
you still use a literal to find the value ;)

You could probably guess than I'm creating a textbox script.
So of course, the order in which you give me the messages is important ;)
 
Top