{"id":10693,"date":"2011-05-11T07:00:00","date_gmt":"2011-05-11T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2011\/05\/11\/why-double-null-terminated-strings-instead-of-an-array-of-pointers-to-strings\/"},"modified":"2011-05-11T07:00:00","modified_gmt":"2011-05-11T07:00:00","slug":"why-double-null-terminated-strings-instead-of-an-array-of-pointers-to-strings","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20110511-00\/?p=10693","title":{"rendered":"Why double-null-terminated strings instead of an array of pointers to strings?"},"content":{"rendered":"<p>I mentioned this in passing in my description of <a href=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2009\/10\/08\/9904646.aspx\"> the format of double-null-terminated strings<\/a>, but I think it deserves calling out.\n Double-null-terminated strings may be difficult to create and modify, but they are very easy to serialize: You just write out the bytes as a blob. This property is very convenient when you have to copy around the list of strings: Transferring the strings is a simple matter of transferring the memory block as-is. No conversion is necessary. This makes it easy to do things like wrap the memory inside another container that supports only flat blobs of memory.\n As it turns out, a flat blob of memory is convenient in many ways. You can copy it around with memcpy. (This is important when capturing values across security boundaries.) You can save it to a file or into the registry as-is. It marshals very easily. It becomes possible to store it in an <code>IData&shy;Object<\/code>. It can be freed with a single call. And in the cases where you can&#8217;t allocate any memory at all (<i>e.g.<\/i>, you&#8217;re filling a buffer provided by the caller), it&#8217;s one of the few options available. This is also why <a href=\"http:\/\/msdn.microsoft.com\/aa374807.aspx\"> self-relative security descriptors<\/a> are so popular in Windows: Unlike absolute security descriptors, self-relative security descriptors can be passed around as binary blobs, which makes them easy to marshal, especially if you need to pass one from kernel mode to user mode.\n <a href=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2009\/10\/08\/9904646.aspx#9905474\"> A single memory block with an array of integers containing offsets would also work<\/a>, but as the commenter noted, it&#8217;s even more cumbersome than double-null-terminated strings.<\/p>\n<p> Mind you, if you don&#8217;t need to marshal the list of strings (because it never crosses a security boundary and never needs to be serialized), then an array of string pointers works just fine. If you look around Win32, you&#8217;ll find that most cases where double-null terminated strings exist are for the most part either inherited from 16-bit Windows or are one of the cases where marshalling is necessary. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>I mentioned this in passing in my description of the format of double-null-terminated strings, but I think it deserves calling out. Double-null-terminated strings may be difficult to create and modify, but they are very easy to serialize: You just write out the bytes as a blob. This property is very convenient when you have to [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-10693","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>I mentioned this in passing in my description of the format of double-null-terminated strings, but I think it deserves calling out. Double-null-terminated strings may be difficult to create and modify, but they are very easy to serialize: You just write out the bytes as a blob. This property is very convenient when you have to [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/10693","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=10693"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/10693\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=10693"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=10693"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=10693"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}