initializing a huge multidimensional array

Posted By: Chaeon

initializing a huge multidimensional array - 11/12/11 02:37

I have a great big list of numbers which i want to store in an array when my program first starts, so that a variety of functions may read from it later. let's say the array is 10x200.

I don't want to type it in like this.

var name[n] = { value_1, value_2, ... value_n };

I don't think that's neat or efficient, to have 2000 numbers in a huge block at the beginning of my script!

One idea i had were to have them in an external text file, and use a loop to copy each number into my array at the beginning.

Another idea was to do the same with an image file.

What do you think would be the neatest way to do this?

Thanks for your time laugh
Posted By: texcoord3

Re: initializing a huge multidimensional array - 11/12/11 03:38

yes, reading from a file is a wonderful idea! In fact, that's how objects like 3d models and textures are generally read into memory.

I would use a plain text or compressed text file to read from, not a texture file (unless you want to read in a texture) since texture file will generally have a specific storage format which you might not need. For example if you don't want the trouble of parsing the red, green, blue from a .bmp file then it would just be easier to read from text. Also some formats may be compressed like .tga or .dds so you should be careful with texture/image files when loading.
Posted By: Chaeon

Re: initializing a huge multidimensional array - 11/12/11 06:01

okay i'll do it by an ordinary text file then. File_var_read seems totally perfect for this. thank you!
Posted By: EvilSOB

Re: initializing a huge multidimensional array - 11/12/11 11:43

Depending on how you are collecting this information initially,
FILE_LOAD may also be helpful for you too.

If you can get the data into gamestudio ONCE, then you can use FILE_SAVE
to store the entire array to a binary file.
This file can then be FILE_LOADed straight into your array later.
© 2024 lite-C Forums