{"id":43,"date":"2014-07-03T08:32:59","date_gmt":"2014-07-03T08:32:59","guid":{"rendered":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdev\/?p=43"},"modified":"2014-07-08T08:32:55","modified_gmt":"2014-07-08T08:32:55","slug":"the-ovm_vbstr_t-type","status":"publish","type":"post","link":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdev\/?p=43","title":{"rendered":"The ovm_vbstr_t type"},"content":{"rendered":"<p>The <code>ovm_vbstr_t<\/code> type is the OrchIDS type of <strong>virtual<\/strong> binary strings. Binary strings are fixed-size arrays of bytes, and are implemented as the <a title=\"The ovm_bstr_t type\" href=\"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdev\/?p=38\"><code>ovm_bstr_t<\/code><\/a> type.\u00a0 On the opposite, virtual binary strings are merely pointers to a subinterval of an actual binary string.<!--more--><\/p>\n<p>It is defined this way in src\/lang.h:<\/p>\n<pre>typedef struct ovm_vbstr_s ovm_vbstr_t;\r\nstruct ovm_vbstr_s\r\n{\r\n  gc_header_t gc;\r\n  ovm_var_t *delegate;\r\n  size_t    len;\r\n  uint8_t  *str;\r\n};<\/pre>\n<p>Typically, the <code>delegate<\/code> field will be a non-<code>NULL<\/code> object of type <code>ovm_bstr_t<\/code>, holding a binary string; the <code>str<\/code> field points into the latter string, and the <code>len<\/code> field is meant to tell how many bytes we wish to actually consider for a substring.  In general, if the <code>delegate<\/code> field is non-<code>NULL<\/code>, it should be an object that should be marked by the garbage collector if we wish the <code>str<\/code> field to keep pointing to some valid data at all.<\/p>\n<p>If the <code>delegate<\/code> field is <code>NULL<\/code>, then the <code>str<\/code> field must point into some global, constant array of bytes.\u00a0 Don&#8217;t make it point to any other kind of data: if you deallocate the latter (either manually, or if you let the garbage collector do it), <code>str<\/code> will be left as a dangling pointer.<\/p>\n<p>The type <code>ovm_vbstr_t<\/code> is a type of <a title=\"Garbage collection\" href=\"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdev\/?p=18\">garbage-collectable<\/a> data. To allocate a new object of type <code>ovm_vbstr_t<\/code>, use the function:<\/p>\n<pre>ovm_var_t *ovm_vbstr_new(gc_t *gc_ctx, ovm_var_t *delegate);<\/pre>\n<p>This creates a new <code>ovm_vbstr_t<\/code> object, with the given <code>delegate<\/code>. Calling <code>res<\/code> the result, one always has <code>TYPE(res)==T_VBSTR<\/code>. The actual <code>len<\/code> and <code>str<\/code> fields are left uninitialized. One can access them using <code>VBSTRLEN(res)<\/code> and <code>VBSTR(res)<\/code>, respectively, both to write into or to read from.<\/p>\n<p>The return type of <code>ovm_vbstr_new()<\/code> is the universal type <a title=\"The ovm_var_t universal type\" href=\"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdev\/?page_id=121\"><code>ovm_var_t<\/code><\/a> instead of <code>ovm_vbstr_t<\/code>, for practical reasons.<\/p>\n<p>The result is created white, and much be <code>gc_touch()<\/code>ed before storing it into a garbage-collectable object.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The ovm_vbstr_t type is the OrchIDS type of virtual binary strings. Binary strings are fixed-size arrays of bytes, and are implemented as the ovm_bstr_t type.\u00a0 On the opposite, virtual binary strings are merely pointers to a subinterval of an actual binary string.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,4],"tags":[],"class_list":["post-43","post","type-post","status-publish","format-standard","hentry","category-data-types","category-virtual-machine"],"_links":{"self":[{"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdev\/index.php?rest_route=\/wp\/v2\/posts\/43","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdev\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdev\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdev\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdev\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=43"}],"version-history":[{"count":8,"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdev\/index.php?rest_route=\/wp\/v2\/posts\/43\/revisions"}],"predecessor-version":[{"id":148,"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdev\/index.php?rest_route=\/wp\/v2\/posts\/43\/revisions\/148"}],"wp:attachment":[{"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdev\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=43"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdev\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=43"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdev\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=43"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}