Help with MemoryBlock and ValueTree


#1

Hi, I have a big amount of data in a project that needs be written. To be exact, I need to write 16 x 16 x 16 x 64 x 90 = 23 Megabytes.

My original idea was creating a ValueTree, since it’s an structure of classes and subclasses. However it last around 300 seconds into creating the ValueTree and convert it to binary (more when I read the binary). Too much. Then I tried to write a MemoryBlock with the lastes 64 x 90 bytes.

This is the function I’m using to write it:

`  MemoryBlock memBlock;
   for (int8 i=0; i<64; ++i)
   {
      const Car* const currentCar= m_cars.getUnchecked(i);
         for (int8 j=0; j<90; ++j)
         {
            const int8 currentProp = currentCar->getProperties(j);
            memBlock.append(&currentProp, 1);     // Maybe this is CRAZY!!
         }
      }
   }

   ValueTree tree("AllCars"); 
   tree.setProperty("S", memBlock, 0);  // I will write few more properties later, but only a bunch.

And this one is how I read it once I convert the root MemoryBlock to a ValueTree:

   const var* const properties = tree.getPropertyPointer("S"); 
   MemoryBlock memblock(properties, 64*90);  // Again, maybe this is crazy too,
                                   // but I cannot figure myself how to do it
                  

   int32 index = 0;
   for (int8 i=0; i<64; ++i)
   {
      Car* const currentCar = m_cars.getUnchecked(i);
      for (int8 j=0; j<90; ++j)
      {
         const int8 xx = memblock[index];
         currentCar->setProperty(j, xx);
         ++index;
      }
   }

While the writting to the memory Block is much faster than saving a ValueTree with lots of properties and child, it crashes with the loading code [in memcpy.asm], and I cannot figure the reason. Please, could you help me?


#2

Maybe try using MemoryOutputStream/MemoryInputStream?


#3

Yes, I use that once I have the ValueTree completed, with all the MemoryBlocks inside.

I found the mistake: I was forgotting to use var::getBinaryData() to obtain the MemoryBlock. These lines are wrong. Wow, I spend the entire day to find the mistake! :stuck_out_tongue:

const var* const properties = tree.getPropertyPointer("S"); 
MemoryBlock* memblockp = properties->getBinaryData();
MemoryBlock& mbl = *memblockp;

Thank you for the reply anyway! :slight_smile: