[Development] Storing and managing ValueArray inside QV4::Heap objects

Valery Kotov kotov.valery at gmail.com
Wed Aug 8 09:10:43 CEST 2018


Hello all,

I have a question about QV4 heap objects and what could be stored in them.
I would like to move data structure from c++ heap to GC heap.
Unfortunately, my data structure stores a pair of QLists internally.
As far as I'm aware, QV4::Heap objects should be "trivially constructible",
and thus, cannot store QList(s).
One option would be to store QList pointer and manage it's lifecycle
manually. But that does not sound like a good idea.
I've noticed though, that some of qv4 types are using DECLARE_MARKOBJECTS
macro. By using DECLARE_MARKOBJECTS macro and ObjectMember(s) define I can
actually store a ValueArray member in my QV4 heap object.

#define MyObjectMembers(class, Member) \
    Member(class, ValueArray, ValueArray, myValues)

DECLARE_HEAP_OBJECT(MyObject, Object) {
    DECLARE_MARKOBJECTS(MyObject);

In this case I can refer to myValues ValueArray type inside of MyObject.
Unfortunately, it is a little bit unclear to me how to manage ValueArrays.
>From what I can see from some examples in the code (qv4generatorobject,
qv4arraydata), it seems that I need to manage ValueArray manually.
What I'm missing at the moment a little bit is how the actually allocation
for ValueArray.values is done.
I suspect that it is probably not done via plain "new" call. Otherwise it
is a little bit confusing why not just to store the pointer directly.

Could you guys please give me a few hints how to go about ValueArray
management?

Thank you!
Sincerely yours,
Valery Kotov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20180808/79c9434c/attachment.html>


More information about the Development mailing list