Home AMX User Forum AMX General Discussion

Dynamically Sized Array?

Is there any way in AMX to have an array that is as big as I need it, but no more?

I'm controlling a MediaPOINTE recorder. I need to get a list of the active files on the device, but the number of files is going to change all the time as they record new things. There's no limit to the number of files it can record. I want to have an array of the names of all of the files that I display on the panel, so that the user can see the names of files and select one and play it. I've got all the logic figured out to display it on the screen and cycle through it, but what I don't have is the ability to make my array big enough for them to have 200 files.

Should I just declare an array big enough for them to have like 1000 files on there and hope they don't hit it, or is there actually a way to make my array sizing dynamic?

J

Comments

  • a_riot42a_riot42 Posts: 1,624
    Does SET_LENGTH_ARRAY not work?
  • viningvining Posts: 4,368
    Jeff wrote:
    Should I just declare an array big enough for them to have like 1000 files on there and hope they don't hit it, or is there actually a way to make my array sizing dynamic?
    AFAK there is no dynamic memory allocation, you have to set a max array size and as you said , hopefully not fill it. Use the set_length_array as Paul suggested to set the current working size needed but you can't go beyong the max value set at compile time.
  • Joe HebertJoe Hebert Posts: 2,159
    We can?t dynamically size arrays in Netlinx; we have to determine the maximum size ahead of time. You can use SET_LENGTH_ARRAY to alter the length but you can never exceed what is declared as vining pointed out.

    I?m not familiar with MediaPOINTE so I don?t know how easy it is to retrieve data but you may want to consider querying the device dynamically for one ?page? of data a time.

    If you take that approach (assuming the device can handle it) then your array only has to be big enough to hold the maximum amount of data that you can display on the touch screen at any given time. It won?t matter if there are 2 recordings or 2 million recordings; the code is inherently scalable with no wasted memory. This is the type of approach to take when interfacing with a device like the iPod.

    If the paging approach isn?t possible for your situation then you might want to consider writing the data to disk and retrieve as needed. Or you might just have to say the heck with it and declare your array way big enough within reason knowing there is a built in limitation.
  • travtrav Posts: 188
    They do have something....

    I hear Duet calling you.......
  • DHawthorneDHawthorne Posts: 4,584
    When feasible, I've made the aray dimension the largest I think that could possibly be needed, then used an option variable to limit the specific application. For example: an Aprilaire thermostat buss can have a max of 32 thermostats, so I make the array storing stat data have a dimension of 32, then for each particular job that uses the module, pass it a variable to tell it my actual number of thermostats. Of course, 32 is not that big of a number; if you are talking sizes of 1000 with nested arrays, you are going to have a lot of wasted memory allocation.
  • ericmedleyericmedley Posts: 4,177
    I suppose one could sort of create something like this by storing the array as a file or files in the disk memory. Then it could grow or shrink as you wish. (of course you're still limited in the amount of diskram you have. Access time would become an issue. But there are ways around that as well.
  • a_riot42a_riot42 Posts: 1,624
    Jeff wrote: »
    There's no limit to the number of files it can record.

    Unless they know something noone else does, there is always a limit. Mayeb you can find out what it is and go from there, but a dynamic system might be better as others have described.
    Paul
Sign In or Register to comment.