On Sat, 6 Dec 2014, Sebastian Lackner wrote:
On 06.12.2014 17:48, Martin Storsjö wrote:
On Sat, 6 Dec 2014, Sebastian Lackner wrote:
Hi Martin,
please note that besides functions like WindowsSubstring which implicitly manipulate the string buffer, there are also some functions for explicit string buffer management:
WindowsPreallocateStringBuffer - allocate a new string buffer with refcount 1 WindowsPromoteStringBuffer - create a new string based on an existing string buffer without incrementing refcount WindowsDeleteStringBuffer - decrement the refcount of a string buffer
Yep, I saw these as well. Although the MSDN page for WindowsDeleteStringBuffer doesn't talk about refcounts anywhere I can see.
Is the only way of using these string buffers to allocate a certain size, modify the WCHAR* that WindowsPreallocateStringBuffer returned, or are there any other functions involved with these as well?
// Martin
No, there are no further functions involved. The idea behind this is that all WindowsStrings are immutable, and cannot (= should not) be modified anymore after a HSTRING was assigned. Allocating first the string buffer, and later promoting to a HSTRING allows to savely modify the contents (for example reading it from a file). I guess this is mainly for performance reasons, otherwise the content would always have to be copied.
Indeed, but since you don't seem to be able to change the length of the allocated HSTRING_BUFFER, I don't see much of the idea in that API (for e.g. creating strings dynamically), except for avoiding a copy when it is made into a HSTRING. But I guess that was an important enough usecase to warrant that API.
Anyway, I should be able to fit in support for these functions as well without any bigger issues.
// Martin