What exactly is the Dart_Handle type?

62 views
Skip to first unread message

Benjamin Summerton (@def-pri-pub)

unread,
Oct 4, 2016, 2:06:58 PM10/4/16
to Dart Misc
I've been a little interested lately in doing some Dart native development, and everywhere I've seen this `Dart_Handle` type.  When poking through through the source, this is all that I could find on it.  Which is just a typdef to a `_Dart_Handle *`, which I couldn't find anything else on in the SDK repo.

So my question is the title of the topic: "What exactly is the Dart_Handle type?"

Michael Francis

unread,
Oct 4, 2016, 2:12:59 PM10/4/16
to Dart Misc
Dart_Handle is a reference to a Dart Object. To use the Dart_Handle you will need to use the other methods found in dart_api.h
Starting about line number 1361 you will begin to see functions that translate a Dart_Handle to c types.

On Tue, Oct 4, 2016 at 2:07 PM Benjamin Summerton (@def-pri-pub) <def.p...@gmail.com> wrote:
I've been a little interested lately in doing some Dart native development, and everywhere I've seen this `Dart_Handle` type.  When poking through through the source, this is all that I could find on it.  Which is just a typdef to a `_Dart_Handle *`, which I couldn't find anything else on in the SDK repo.

So my question is the title of the topic: "What exactly is the Dart_Handle type?"

--
For other discussions, see https://groups.google.com/a/dartlang.org/
 
For HOWTO questions, visit http://stackoverflow.com/tags/dart
 
To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+uns...@dartlang.org.

William Hesse

unread,
Oct 4, 2016, 3:50:35 PM10/4/16
to General Dart Discussion
To be more clear about the purpose of Dart_Handle:

Because Dart has a garbage-collected heap of objects, and the garbage collector can move objects around, you can't keep pointers to objects in C++ code that could be interrupted by garbage collections.  So you allocate Dart_Handles, which are a bunch of places THAT THE GC KNOWS ABOUT holding pointers to objects.  That way, when the GC moves an object, it updates the pointer in that place (that Dart_Handle).  So your C++ code, but more importantly the Dart embedding API calls that your code makes, can grab the object pointer out of that handle and do stuff with it (but reloading the pointer from the handle any time a GC could have happened).

The Dart_Handles that the GC knows about can be created in various ways: in Zones, as permanent handles, etc.  You can't just make one using 'new'.  The memory management of the handles has to be done more carefully and explicitly, and they aren't GCd, since their reason for existing is to be a C++ pointer that isn't touched by the GC, that points to a Dart object pointer.
--
William Hesse
Reply all
Reply to author
Forward
0 new messages