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
Of course there are a lot more internal functions, but I think it should give a rough idea of how everything works on Windows. If you need any help with implementing this feel free to ask, we're also interested in this functionality. ;)
Regards, Sebastian
On 06.12.2014 17:26, Martin Storsjö wrote:
Hi Michael,
On Sat, 6 Dec 2014, Michael Müller wrote:
you are right that WindowsSubstring always creates a new backing buffer (although it is not necessary), but there is also WindowsDuplicateString. This function indeed uses the same backing buffer as you can verify with this small sample code: https://dl.dropboxusercontent.com/u/61413222/test-string.c
The MSDN also explicitly mentions that the refcount is incremented in this case: "If string was created by calling the WindowsCreateString function, the reference count of the backing buffer is incremented. If string was created by calling the WindowsCreateStringReference function, the Windows Runtime copies its source string to a new buffer and starts a reference count, which means that newString is not a fast-pass string." Source: http://msdn.microsoft.com/en-us/library/br224634(v=vs.85).aspx
It is necessary to implement reference counting in order to be fully compatible with the Windows implementation.
Oh, I see - I hadn't checked this particular function (yet).
Ok then, then it's clear where/how to hook up the reference counting. I'll see if I can get to attempting implementing this sometimes soon.
// Martin