mikee47 / ConfigDB

Configuration database for Sming
GNU General Public License v3.0
2 stars 1 forks source link

Don't store pointers in objects #10

Closed mikee47 closed 4 weeks ago

mikee47 commented 4 weeks ago

Keeping pointers in Object gets broken when array memory reallocated. This PR fixes that by changing to a 16-bit 'reference' value which parent resolves to pointer as required. For structures this is just an offset in the parent structure, for arrays, it's an index.

There doesn't seem to be any way to tell the compiler that ArrayId can be misaligned. This causes problems on the Esp8266. So this is now defined as a packed struct. Note that we could just define it as uint8_t as we probably don't need more than 255 items, but no real need to restrict array sizes for those devices with lots of RAM.

Arrays have been simplified and the ArrayBase class added as a base for both Array and ObjectArray.

Insertion and deletion supported, plus operator[] for both read/write.