Store portions of memory in var


#1

ValueTree is so useful, i use it as base for my interprocess-messaging system, but it would be cool if you could extend the var type:

“var” should also be able to store any kind of binary data (MemoryBlock)


#2

also it would nice to have Constructors for

Array
Array
Array
Array etc…

At the moment i have to convert a Array into a Array before i can store it in a ValueTree, or is there a faster method…


#3

okay two handy converter:

template <class ObjectClass>
static Array<var> convertIntoVarArray(Array< ObjectClass > &arrayToConvert)
{
	Array<var> newArray;
	for (int i=0; i<arrayToConvert.size(); i++)
	{
		newArray.add(var(arrayToConvert[i]));		
	};
	return newArray;
}

template <class ObjectClass>
static Array<ObjectClass> convertFromVarArray(Array< var > &arrayWhereToConvertFrom)
{
	Array< ObjectClass > newArray;
	for (int i=0; i<arrayWhereToConvertFrom.size(); i++)
	{
		newArray.add(ObjectClass(arrayWhereToConvertFrom[i]));
	};

	return newArray;
}

#4

Just create yourself a subclass of DynamicObject which stores whatever block of memory you need (or better still, stores your data in a structured form).


#5

but can i use writeToStream() or/and create a XML/JSON from it?
Its all about serializing and send it over the network.


#6

[quote=“chkn”]but can i use writeToStream() or/and create a XML/JSON from it?
Its all about serializing and send it over the network.[/quote]

Well no, but this was never intended as a way of serialising large blocks of unstructured data. Your best bet is probably to uuencode it and store it as a string.


#7

what you call “large blocks of unstructured data” is in my case a “atomic portion of binary data”, which is exactly the kind of information i need to store. Its very close to a string.
If i uuencode it a string its just wasting memory/performance .