Home AMX User Forum NetLinx Studio
Options

Define_Type overhead

Does anyone know how much overhead is involved with creating structures? The reason I ask is that I currently use 4 different structures to house a bunch of configuration information. I am finding that I need to occasionally add items to the structure. The problem arises in that I am currently using the variable_to_string function to store the configuration to disk and I don't think I can retrieve the data if I change the structure. (I cannot use variable_to_xml because of flaws in the function)

The way I am trying to solve this is by using a version file that indicates what version the data was saved as. I then use that to read the data into a stack_var of the correct version type and then populate the current structure accordingly. Right now, I only have 2 or 3 versions of each structure, so I doubt that the extra structure definitions will cause problems, but I wanted to make sure. I am also thinking about the future and trying to decide how many previous versions I will let the program automatically convert.

I can always write a separate program that simply goes through and updates the files, but I kind of like the ability to restore backup files on the fly as long as they are within a couple versions of the current.

Jeff

Comments

  • Options
    DHawthorneDHawthorne Posts: 4,584
    My guess would be when you define a structure the metadata that contains the names of each member and size of each is stored somewhere in memory, and the memory space for each variable using the structure only contains the actual data. So, the actual overhead for variable storage wouldn't be any bigger than the data itself ... the metadata for the storage conventions only appears once and is relatively negligible.

    As for your other issue, I usually find it best to break the structures into a more generic form. My preference is to feed the data out into a CVS file, then read it back in when the module loads. Then you could put your version number right in the first CVS record, and interpret it accordingly as it's read ... when you write the data out again, it can automatically update the version accordingly.
  • Options
    a_riot42a_riot42 Posts: 1,624
    Spire_Jeff wrote: »
    The problem arises in that I am currently using the variable_to_string function to store the configuration to disk and I don't think I can retrieve the data if I change the structure. (I cannot use variable_to_xml because of flaws in the function)

    I would not use a binary data store for the reason you mentioned. Simple text is the most flexible if you come up with your own scheme, depending on the data. I have abandoned structures except in limited cases and use only arrays now. Until they change things so that structures can be passed to modules and functions I will use arrays.
    Paul
Sign In or Register to comment.